/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 '' && REFACTOR_WF=0 && INJECT_WF=0 && 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}' && REFACTOR_WF=1; fi && if [ -f .inject-knowledge-extracted ] || [ -f .inject-plan-approved ] || [ -f .inject-execution-done ]; then echo ' ⚠️ In-progress injection workflow:' && ls -la .inject-* 2>/dev/null | awk '{print \" \" $NF}' && INJECT_WF=1; fi && if [ $REFACTOR_WF -eq 0 ] && [ $INJECT_WF -eq 0 ]; then echo ' ✓ No workflow in progress'; else echo '' && echo ' Keep state files to continue in next session' && echo ' To cancel: rm .refactor-* .inject-*'; 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 \"feat/refactor: ...\"' && echo ' → Rollback: git checkout -- .' && echo '' && if [ ! -f .refactor-audit-passed ] && [ ! -f .inject-execution-done ]; then echo ' 🚫 Recommend verification before commit!' && echo ' → Run /serena-refactor:audit'; 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"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"knowledge-extractor\"* ]] && exit 0; echo '' && echo '════════════════════════════════════════════════════════════' && echo ' 📚 KNOWLEDGE EXTRACTION - Starting Extraction' && echo '════════════════════════════════════════════════════════════' && echo '' && echo ' Extraction targets:' && echo ' • Project structure and modules' && echo ' • Symbol definitions and relationships' && echo ' • Design patterns and conventions' && echo ' • Dependency graph' && echo '════════════════════════════════════════════════════════════'",
"timeout": 5
}
],
"matcher": "Task"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"feature-planner\"* ]] && exit 0; echo '' && echo '════════════════════════════════════════════════════════════' && echo ' 📋 FEATURE PLANNING - Pre-Planning Verification' && echo '════════════════════════════════════════════════════════════' && echo '' && if [ ! -f .inject-knowledge-extracted ]; then echo ' ⚠️ WARNING: Planning without knowledge extraction'; echo ' → Recommended: Run /serena-refactor:extract first'; else echo ' ✓ Knowledge extraction confirmed'; fi && echo '════════════════════════════════════════════════════════════'",
"timeout": 5
}
],
"matcher": "Task"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"code-injector\"* ]] && exit 0; echo '' && echo '════════════════════════════════════════════════════════════' && echo ' 💉 CODE INJECTION - Workflow Verification' && echo '════════════════════════════════════════════════════════════' && echo '' && BLOCKED=0 && if [ ! -f .inject-plan-approved ]; then echo ' ❌ BLOCKED: Feature plan not approved'; echo ' → Run feature-planner and approve plan first'; BLOCKED=1; else echo ' ✓ Feature 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 ' 🚫 Injection blocked due to workflow violation.' && echo '════════════════════════════════════════════════════════════' && exit 1; else echo ' ✓ All conditions met - Injection allowed' && echo '════════════════════════════════════════════════════════════'; fi",
"timeout": 10
}
],
"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"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"knowledge-extractor\"* ]] && exit 0; touch .inject-knowledge-extracted && echo '' && echo '════════════════════════════════════════════════════════════' && echo ' ✓ Knowledge Extraction Complete - State Saved' && echo '' && echo ' [.inject-knowledge-extracted] created' && echo '' && echo ' Next steps:' && echo ' → Run feature-planner with feature description' && echo ' → Or /serena-refactor:inject [feature]' && echo '════════════════════════════════════════════════════════════'",
"timeout": 5
}
],
"matcher": "Task"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"feature-planner\"* ]] && exit 0; touch .inject-plan-approved && echo '' && echo '════════════════════════════════════════════════════════════' && echo ' ✓ Feature Plan Created' && echo '' && echo ' [.inject-plan-approved] created' && echo ' → Plan auto-approved.' && echo ' → If issues found, run: rm .inject-plan-approved' && echo '' && echo ' Next steps:' && echo ' → Review the plan carefully' && echo ' → Run code-injector to execute' && echo '════════════════════════════════════════════════════════════'",
"timeout": 5
}
],
"matcher": "Task"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"code-injector\"* ]] && exit 0; touch .inject-execution-done && echo '' && echo '════════════════════════════════════════════════════════════' && echo ' ✓ Code Injection Complete' && echo '' && echo ' [.inject-execution-done] created' && echo '' && echo ' ⚠️ Recommended: Verify injected code' && echo ' → Run syntax check / linter' && echo ' → /serena-refactor:audit for quality verification' && echo '' && echo ' After verification:' && echo ' → git diff to review changes' && echo ' → git add . && git commit -m \"feat: [description]\"' && echo '════════════════════════════════════════════════════════════'",
"timeout": 5
}
],
"matcher": "Task"
},
{
"hooks": [
{
"type": "command",
"command": "INPUT=$(cat); SUBAGENT=$(echo \"$INPUT\" | jq -r '.tool_input.subagent_type // \"\"'); [[ \"$SUBAGENT\" != *\"code-injector\"* ]] && exit 0; OUTPUT=$(echo \"$INPUT\" | jq -r '.tool_result // \"\"'); echo \"$OUTPUT\" | grep -qE '\"status\":\\s*\"success\"|status.*success' || exit 0; rm -f .inject-knowledge-extracted .inject-plan-approved 2>/dev/null && echo '' && echo ' ✓ Injection workflow state cleaned (success)'",
"timeout": 5
}
],
"matcher": "Task"
}
]
}{
"riskFlags": {
"touchesBash": false,
"matchAllTools": false,
"touchesFileWrites": false
},
"typeStats": {
"command": 21
},
"eventStats": {
"Stop": 1,
"PreToolUse": 9,
"PostToolUse": 11
},
"originCounts": {
"absolutePaths": 0,
"pluginScripts": 0,
"projectScripts": 0
},
"timeoutStats": {
"commandsWithoutTimeout": 0
}
}