Skip to content

Commit 9756ea2

Browse files
committed
fix(hooks): add auto mode detection for PLAN/ACT/EVAL/AUTO keywords
Add UserPromptSubmit hook that automatically detects workflow mode keywords at the start of user prompts and injects context to trigger parse_mode MCP call. resolve #270
1 parent 3c08f29 commit 9756ea2

11 files changed

Lines changed: 1096 additions & 1 deletion
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
# PLAN/ACT/EVAL 패턴 자동 감지 설계
2+
3+
## 개요
4+
5+
사용자가 "PLAN:", "ACT:", "EVAL:", "AUTO:" 패턴으로 메시지를 시작할 때 자동으로 `parse_mode` MCP 함수를 호출하도록 하는 기능 설계.
6+
7+
## 문제점
8+
9+
- 현재 `/plan`, `/act`, `/eval` 명령어로만 모드 전환 가능
10+
- "PLAN: something" 형태의 자연스러운 입력이 인식되지 않음
11+
- CLAUDE.md에 지시사항이 있으나 일관성 없이 동작
12+
13+
## 해결 방안: UserPromptSubmit Hook + SessionStart 자동 설치
14+
15+
### 아키텍처
16+
17+
```
18+
┌─────────────────────────────────────────────────────────────────┐
19+
│ Claude Code 세션 시작 │
20+
└─────────────────────────────────────────────────────────────────┘
21+
22+
23+
┌─────────────────────────────────────────────────────────────────┐
24+
│ SessionStart Hook 실행 │
25+
│ (플러그인의 hooks/session-start.py) │
26+
│ ┌───────────────────────────────────────────────────────────┐ │
27+
│ │ 1. ~/.claude/hooks/ 디렉토리 존재 확인 │ │
28+
│ │ 2. codingbuddy-mode-detect.py 존재 확인 │ │
29+
│ │ 3. 없으면 → 플러그인에서 복사 & 권한 설정 │ │
30+
│ │ 4. ~/.claude/settings.json 훅 설정 확인/추가 │ │
31+
│ │ 5. 결과 메시지 출력 (설치됨/이미 존재) │ │
32+
│ └───────────────────────────────────────────────────────────┘ │
33+
└─────────────────────────────────────────────────────────────────┘
34+
35+
36+
┌─────────────────────────────────────────────────────────────────┐
37+
│ 사용자 입력 │
38+
│ "PLAN: 리뷰 수집 로직 변경하고 싶어" │
39+
└─────────────────────────────────────────────────────────────────┘
40+
41+
42+
┌─────────────────────────────────────────────────────────────────┐
43+
│ UserPromptSubmit Hook │
44+
│ ┌───────────────────────────────────────────────────────────┐ │
45+
│ │ 1. stdin으로 JSON 입력 받음 │ │
46+
│ │ 2. prompt 필드에서 패턴 감지 │ │
47+
│ │ - PLAN|ACT|EVAL|AUTO (영문) │ │
48+
│ │ - 계획|실행|평가|자동 (한글) │ │
49+
│ │ - 計画|実行|評価|自動 (일본어) │ │
50+
│ │ - 计划|执行|评估|自动 (중국어) │ │
51+
│ │ - PLANIFICAR|ACTUAR|EVALUAR|AUTOMÁTICO (스페인어) │ │
52+
│ │ 3. 감지 시 JSON 컨텍스트 출력 │ │
53+
│ └───────────────────────────────────────────────────────────┘ │
54+
└─────────────────────────────────────────────────────────────────┘
55+
56+
57+
┌─────────────────────────────────────────────────────────────────┐
58+
│ Claude 처리 │
59+
│ ┌───────────────────────────────────────────────────────────┐ │
60+
│ │ 주입된 컨텍스트를 보고 parse_mode MCP 호출 │ │
61+
│ │ → CodingBuddy MCP Server가 모드별 지시사항 반환 │ │
62+
│ └───────────────────────────────────────────────────────────┘ │
63+
└─────────────────────────────────────────────────────────────────┘
64+
```
65+
66+
## 파일 구조
67+
68+
```
69+
codingbuddy/ (플러그인 루트)
70+
├── .claude-plugin/
71+
│ └── plugin.json ← hooks 필드 추가
72+
├── commands/
73+
│ ├── plan.md
74+
│ ├── act.md
75+
│ ├── eval.md
76+
│ └── auto.md
77+
├── hooks/ ← 신규 디렉토리
78+
│ ├── session-start.py ← SessionStart: 자동 설치
79+
│ └── user-prompt-submit.py ← UserPromptSubmit: 패턴 감지
80+
├── README.md ← 설치 가이드 업데이트
81+
└── package.json
82+
```
83+
84+
## 다국어 패턴 지원
85+
86+
| Mode | 영어 | 한국어 | 일본어 | 중국어 | 스페인어 |
87+
|------|------|--------|--------|--------|----------|
88+
| PLAN | PLAN | 계획 | 計画 | 计划 | PLANIFICAR |
89+
| ACT | ACT | 실행 | 実行 | 执行 | ACTUAR |
90+
| EVAL | EVAL | 평가 | 評価 | 评估 | EVALUAR |
91+
| AUTO | AUTO | 자동 | 自動 | 自动 | AUTOMÁTICO |
92+
93+
## 구현 세부사항
94+
95+
### 1. user-prompt-submit.py
96+
97+
- 정규식으로 시작 부분만 체크 (성능)
98+
- 대소문자 무시 (`re.IGNORECASE`)
99+
- XML 태그로 컨텍스트 래핑 (파싱 용이)
100+
- 감지 안 되면 아무것도 출력 안 함
101+
102+
### 2. session-start.py
103+
104+
- 플러그인 경로 탐색: 환경변수 → fallback 경로들
105+
- ~/.claude/hooks/ 에 스크립트 복사
106+
- ~/.claude/settings.json 에 훅 등록
107+
- 이미 설치된 경우 스킵
108+
109+
### 3. plugin.json
110+
111+
```json
112+
{
113+
"name": "codingbuddy",
114+
"hooks": {
115+
"SessionStart": "hooks/session-start.py"
116+
}
117+
}
118+
```
119+
120+
## 테스트 계획
121+
122+
1. **단위 테스트** (user-prompt-submit.py)
123+
- 영문 키워드 감지
124+
- 한글 키워드 감지
125+
- 대소문자 무시
126+
- 콜론 없는 경우
127+
- 키워드 없는 경우
128+
129+
2. **통합 테스트** (session-start.py)
130+
- 첫 설치 시 hooks 디렉토리 생성
131+
- 중복 설치 방지
132+
- settings.json 기존 설정 유지
133+
134+
3. **E2E 테스트**
135+
- 플러그인 설치 → 세션 시작 → 훅 설치 확인
136+
- "PLAN: 테스트" 입력 → parse_mode 호출 확인
137+
138+
## 완료 기준
139+
140+
- [ ] 모든 다국어 키워드 (영/한/일/중/스페인어) 감지
141+
- [ ] SessionStart에서 자동 설치 성공
142+
- [ ] settings.json 기존 설정 손상 없음
143+
- [ ] parse_mode MCP 호출 정상 동작
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
{
22
"name": "codingbuddy",
3-
"description": "PLAN/ACT/EVAL workflow, specialist agents, and reusable skills for systematic TDD development",
3+
"description": "PLAN/ACT/EVAL workflow with auto-detection, specialist agents, and reusable skills for systematic TDD development",
44
"author": {
55
"name": "JeremyDev87",
66
"email": "soundbrokaz@kakao.com"
7+
},
8+
"hooks": {
9+
"SessionStart": "hooks/session-start.py"
710
}
811
}

packages/claude-code-plugin/README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,73 @@ If upgrading from version 2.x:
4646
- **EVAL**: Evaluate code quality and suggest improvements
4747
- **AUTO**: Autonomous PLAN → ACT → EVAL cycle
4848

49+
### Auto Mode Detection (New in 3.1)
50+
51+
Start your message with a mode keyword and it will be automatically detected:
52+
53+
```
54+
PLAN: I want to add a new feature
55+
ACT: implement the login form
56+
EVAL: review my authentication code
57+
AUTO: build a dashboard component
58+
```
59+
60+
**Supported Languages:**
61+
62+
| Mode | English | Korean | Japanese | Chinese | Spanish |
63+
|------|---------|--------|----------|---------|---------|
64+
| PLAN | PLAN: | 계획: | 計画: | 计划: | PLANIFICAR: |
65+
| ACT | ACT: | 실행: | 実行: | 执行: | ACTUAR: |
66+
| EVAL | EVAL: | 평가: | 評価: | 评估: | EVALUAR: |
67+
| AUTO | AUTO: | 자동: | 自動: | 自动: | AUTOMÁTICO: |
68+
69+
The hook is automatically installed on first session start. No manual setup required.
70+
71+
#### Manual Installation (Fallback)
72+
73+
If automatic installation doesn't work, you can manually set up the mode detection hook:
74+
75+
```bash
76+
# 1. Create hooks directory
77+
mkdir -p ~/.claude/hooks
78+
79+
# 2. Copy the hook file (from plugin cache)
80+
cp ~/.claude/plugins/cache/jeremydev87/codingbuddy/*/hooks/user-prompt-submit.py \
81+
~/.claude/hooks/codingbuddy-mode-detect.py
82+
83+
# 3. Make it executable
84+
chmod +x ~/.claude/hooks/codingbuddy-mode-detect.py
85+
86+
# 4. Register in settings.json
87+
# Add to ~/.claude/settings.json:
88+
```
89+
90+
```json
91+
{
92+
"hooks": {
93+
"UserPromptSubmit": [
94+
{
95+
"hooks": [
96+
{
97+
"type": "command",
98+
"command": "python3 ~/.claude/hooks/codingbuddy-mode-detect.py"
99+
}
100+
]
101+
}
102+
]
103+
}
104+
}
105+
```
106+
107+
#### Troubleshooting Auto Detection
108+
109+
If mode detection isn't working:
110+
111+
1. **Check hook installation**: Verify `~/.claude/hooks/codingbuddy-mode-detect.py` exists
112+
2. **Check settings.json**: Ensure hook is registered in `~/.claude/settings.json`
113+
3. **Check Python**: Ensure `python3` is available in PATH
114+
4. **Restart Claude Code**: Changes to hooks require session restart
115+
49116
### Commands
50117
- `/plan` - Enter PLAN mode
51118
- `/act` - Enter ACT mode
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)