/plugin marketplace add chkim-su/serena-refactor-marketplace/plugin install serena-refactor@serena-refactor-marketplaceDefined in hooks/hooks.json
{
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "echo '' && echo '════════════════════════════════════════════════════════════' && echo ' 💡 Session Ending - Status Check' && echo '════════════════════════════════════════════════════════════' && echo '' && if [ -f .refactor-analysis-done ] || [ -f .refactor-plan-approved ] || [ -f .refactor-execution-done ]; then echo ' ⚠️ In-progress refactoring workflow:' && ls -la .refactor-* 2>/dev/null | awk '{print \" \" $NF}' && echo '' && echo ' Keep state files to continue in next session' && echo ' To cancel: rm .refactor-*'; else echo ' ✓ No workflow in progress'; fi && echo '' && git rev-parse --git-dir > /dev/null 2>&1 && (git diff --quiet HEAD 2>/dev/null || (echo ' ⚠️ Uncommitted changes:' && echo ' → Save: git commit -m \"refactor: ...\"' && echo ' → Rollback: git checkout -- .' && echo '' && if [ ! -f .refactor-audit-passed ]; then echo ' 🚫 No commits without verification!' && echo ' → Run /serena-refactor:audit first'; fi)) && echo '════════════════════════════════════════════════════════════' || true",
"timeout": 10
}
]
}
],
"PreToolUse": [
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"serena-gateway\"* ]] && exit 0; echo \"$INPUT\" | jq -r '.tool_input.prompt // \"\"' | grep -qi 'MODIFY' || exit 0; echo '' && echo '════════════════════════════════════════════════════════════' && echo ' 🔒 MODIFICATION GATE - Modification Request Detected' && echo '════════════════════════════════════════════════════════════' && echo '' && if [ -f .refactor-plan-approved ]; then echo ' ✓ Plan approved'; else echo ' ⚠️ Plan not approved - Run /serena-refactor:plan first'; fi && git rev-parse --git-dir > /dev/null 2>&1 && (git diff --quiet HEAD 2>/dev/null && echo ' ✓ Working directory clean' || echo ' ⚠️ WARNING: Uncommitted changes - Backup recommended!') || echo ' ℹ️ Not a Git repository'",
"timeout": 10
}
],
"matcher": "Task"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"serena-refactor-executor\"* ]] && exit 0; echo '' && echo '════════════════════════════════════════════════════════════' && echo ' 🔧 REFACTOR EXECUTOR - Workflow Verification' && echo '════════════════════════════════════════════════════════════' && echo '' && BLOCKED=0 && if [ ! -f .refactor-analysis-done ]; then echo ' ❌ BLOCKED: Analysis not completed'; echo ' → Run /serena-refactor:analyze first'; BLOCKED=1; else echo ' ✓ Analysis completed'; fi && if [ ! -f .refactor-plan-approved ]; then echo ' ❌ BLOCKED: Plan not approved'; echo ' → Run /serena-refactor:plan and approve'; BLOCKED=1; else echo ' ✓ Plan approved'; fi && git rev-parse --git-dir > /dev/null 2>&1 && (git diff --quiet HEAD 2>/dev/null && echo ' ✓ Git clean' || echo ' ⚠️ Uncommitted changes - git stash recommended') && echo '' && if [ $BLOCKED -eq 1 ]; then echo ' 🚫 Execution blocked due to workflow violation.' && echo '════════════════════════════════════════════════════════════' && exit 1; else echo ' ✓ All conditions met - Execution allowed' && echo '════════════════════════════════════════════════════════════'; fi",
"timeout": 10
}
],
"matcher": "Task"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"refactor-auditor\"* ]] && exit 0; echo '' && echo '════════════════════════════════════════════════════════════' && echo ' 🔍 AUDIT GATE - Pre-Audit Verification' && echo '════════════════════════════════════════════════════════════' && echo '' && if [ ! -f .refactor-execution-done ]; then echo ' ⚠️ No refactoring execution record'; echo ' Audit will proceed, but verify changes exist.'; else echo ' ✓ Refactoring execution confirmed'; fi && echo '' && echo ' Audit items:' && echo ' • Incomplete patterns (TODO/FIXME)' && echo ' • Reference integrity' && echo ' • SOLID improvement' && echo ' • Test passing' && echo '════════════════════════════════════════════════════════════'",
"timeout": 5
}
],
"matcher": "Task"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"refena-planner\"* ]] && [[ \"$SUBAGENT\" != *\"refactor-planner\"* ]] && exit 0; echo '' && echo '════════════════════════════════════════════════════════════' && echo ' 📋 PLAN GATE - Pre-Planning Verification' && echo '════════════════════════════════════════════════════════════' && echo '' && if [ ! -f .refactor-analysis-done ]; then echo ' ⚠️ WARNING: Planning without analysis'; echo ' → Recommended: Run /serena-refactor:analyze first'; else echo ' ✓ Analysis confirmed'; fi && echo '════════════════════════════════════════════════════════════'",
"timeout": 5
}
],
"matcher": "Task"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"duplicate-detector\"* ]] && exit 0; echo '' && echo '════════════════════════════════════════════════════════════' && echo ' 🔎 DUPLICATE DETECTION - Starting Detection' && echo '════════════════════════════════════════════════════════════' && echo '' && echo ' Detection targets:' && echo ' • Clone code (Type 1-3)' && echo ' • Role duplication (similar classes/functions)' && echo ' • Variable/constant duplication' && echo '════════════════════════════════════════════════════════════'",
"timeout": 5
}
],
"matcher": "Task"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"serena-solid-analyzer\"* ]] && exit 0; echo '' && echo '════════════════════════════════════════════════════════════' && echo ' 📊 SOLID ANALYSIS - Starting Analysis' && echo '════════════════════════════════════════════════════════════' && echo '' && echo ' Analysis items:' && echo ' • SRP (Single Responsibility)' && echo ' • OCP (Open-Closed)' && echo ' • LSP (Liskov Substitution)' && echo ' • ISP (Interface Segregation)' && echo ' • DIP (Dependency Inversion)' && echo '════════════════════════════════════════════════════════════'",
"timeout": 5
}
],
"matcher": "Task"
}
],
"PostToolUse": [
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"serena-solid-analyzer\"* ]] && exit 0; touch .refactor-analysis-done && echo '' && echo '════════════════════════════════════════════════════════════' && echo ' ✓ SOLID Analysis Complete - State Saved' && echo '' && echo ' [.refactor-analysis-done] created' && echo '' && echo ' Next steps:' && echo ' → /serena-refactor:plan - Create refactoring plan' && echo ' → /serena-refactor:detect-duplicates - Detect duplicates' && echo '════════════════════════════════════════════════════════════'",
"timeout": 5
}
],
"matcher": "Task"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"refactor-planner\"* ]] && exit 0; touch .refactor-plan-approved && echo '' && echo '════════════════════════════════════════════════════════════' && echo ' ✓ Refactoring Plan Created' && echo '' && echo ' [.refactor-plan-approved] created' && echo ' → Plan auto-approved.' && echo ' → If issues found, run: rm .refactor-plan-approved' && echo '' && echo ' Next steps:' && echo ' → /serena-refactor:refactor - Execute plan' && echo '════════════════════════════════════════════════════════════'",
"timeout": 5
}
],
"matcher": "Task"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"duplicate-detector\"* ]] && exit 0; touch .refactor-analysis-done && echo '' && echo '════════════════════════════════════════════════════════════' && echo ' ✓ Duplicate Detection Complete - State Saved' && echo '' && echo ' [.refactor-analysis-done] updated' && echo '' && echo ' Next steps:' && echo ' → Review detected duplicates' && echo ' → /serena-refactor:plan - Create consolidation plan' && echo '════════════════════════════════════════════════════════════'",
"timeout": 5
}
],
"matcher": "Task"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"serena-refactor-executor\"* ]] && exit 0; touch .refactor-execution-done && echo '' && echo '════════════════════════════════════════════════════════════' && echo ' ✓ Refactoring Execution Complete' && echo '' && echo ' [.refactor-execution-done] created' && echo '' && echo ' ⚠️ Required: Run quality verification' && echo ' → /serena-refactor:audit' && echo '' && echo ' 🚫 No commits until verification passes!' && echo '════════════════════════════════════════════════════════════'",
"timeout": 5
}
],
"matcher": "Task"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"refactor-auditor\"* ]] && exit 0; OUTPUT=$(echo \"$INPUT\" | jq -r '.tool_result // \"\"'); echo \"$OUTPUT\" | grep -qE 'VERDICT: PASS|FINAL VERDICT: PASS' || exit 0; touch .refactor-audit-passed && rm -f .refactor-analysis-done .refactor-plan-approved .refactor-execution-done 2>/dev/null && echo '' && echo '════════════════════════════════════════════════════════════' && echo ' ✅ Audit Passed - QUALITY GATE PASSED' && echo '' && echo ' State files cleaned:' && echo ' ✓ .refactor-audit-passed created' && echo ' ✓ Workflow state files deleted' && echo '' && echo ' Refactoring completed successfully!' && echo '' && echo ' Next steps:' && echo ' → git add -A && git commit -m \"refactor: [description]\"' && echo ' → rm .refactor-audit-passed (after commit)' && echo '════════════════════════════════════════════════════════════'",
"timeout": 5
}
],
"matcher": "Task"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"refactor-auditor\"* ]] && exit 0; OUTPUT=$(echo \"$INPUT\" | jq -r '.tool_result // \"\"'); echo \"$OUTPUT\" | grep -qE 'VERDICT: FAIL|FINAL VERDICT: FAIL' || exit 0; echo '' && echo '════════════════════════════════════════════════════════════' && echo ' ❌ Audit Failed - QUALITY GATE BLOCKED' && echo '' && echo ' Status: Workflow state preserved' && echo ' → .refactor-execution-done remains' && echo '' && echo ' Issues must be fixed:' && echo ' • Remove TODO/FIXME' && echo ' • Complete empty implementations' && echo ' • Verify reference integrity' && echo ' • Ensure tests pass' && echo '' && echo ' Run /serena-refactor:audit again after fixes.' && echo '════════════════════════════════════════════════════════════'",
"timeout": 5
}
],
"matcher": "Task"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"serena-gateway\"* ]] && exit 0; echo \"$INPUT\" | jq -r '.tool_input.prompt // \"\"' | grep -qi 'MODIFY' || exit 0; echo '' && echo ' ✓ Serena modification complete' && echo ' ℹ️ Reference integrity auto-maintained by Serena Gateway'",
"timeout": 5
}
],
"matcher": "Task"
}
]
}{
"riskFlags": {
"touchesBash": false,
"matchAllTools": false,
"touchesFileWrites": false
},
"typeStats": {
"command": 14
},
"eventStats": {
"Stop": 1,
"PreToolUse": 6,
"PostToolUse": 7
},
"originCounts": {
"absolutePaths": 0,
"pluginScripts": 0,
"projectScripts": 0
},
"timeoutStats": {
"commandsWithoutTimeout": 0
}
}