[Phase 17-C] 훅 시스템 고도화 — 11종 이벤트 연결 + Prompt 모드 구현

AppSettings.AgentConfig.cs:
- ExtendedHooksConfig에 4개 이벤트 추가:
  preToolUse, postToolUse, postToolUseFailure, agentStop

AgentLoopService.ExtendedHooks.cs (신규, 150줄):
- RunExtendedEventAsync(): 이벤트 훅 실행, 결과(additionalContext) 시스템 메시지 주입, HookFired 이벤트 로그
- GetExtendedHooks(): 설정에서 HookEventKind별 런타임 엔트리 조회
- ConvertToRuntimeEntries(): ExtendedHookEntryConfig → ExtendedHookEntry 변환
- ApplyExtendedHookResult(): additionalContext in-place 주입 (marker 기반 교체)

ExtendedHookRunner.cs:
- RunEventAsync() / ExecuteSingleAsync()에 LlmService? llm 파라미터 추가
- RunPromptHookAsync() 신규: {{tool_name/input/output/user_message/event/session_id}} 치환
  → LLM 호출 → block/deny/차단 감지 시 Block=true 반환
- using AxCopilot.Models 추가

AgentLoopService.cs:
- SessionStart 훅 (fire-and-forget, TaskState init 직후)
- UserPromptSubmit 훅 (동기, Block=true 시 즉시 반환 "⚠ 훅 정책에 의해 차단")
- PreCompact 훅 (적극적 압축 직전, 동기)
- PostCompact 훅 × 2 (기본/적극적 압축 완료 후, fire-and-forget)
- SessionEnd + AgentStop 훅 (finally 블록, fire-and-forget)

AgentLoopService.Execution.cs:
- RunToolHooksAsync() 개선: 레거시 AgentHookRunner 유지
  + ExtendedHookRunner PreToolUse/PostToolUse/PostToolUseFailure 추가
이벤트 커버리지: 11종 완전 연결. Agent 모드는 Phase 18-A 예정.
빌드: 경고 0, 오류 0

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-04 00:14:19 +09:00
parent 2383b1e220
commit 0a58419c8a
6 changed files with 327 additions and 28 deletions

View File

@@ -59,24 +59,40 @@ public class ReflexionConfig
/// <summary>Phase 17-C: 확장 훅 설정.</summary>
public class ExtendedHooksConfig
{
// ── 라이프사이클 이벤트 ──────────────────────────────────────────────
[JsonPropertyName("session_start")]
public List<ExtendedHookEntryConfig> SessionStart { get; set; } = new();
[JsonPropertyName("session_end")]
public List<ExtendedHookEntryConfig> SessionEnd { get; set; } = new();
[JsonPropertyName("agent_stop")]
public List<ExtendedHookEntryConfig> AgentStop { get; set; } = new();
[JsonPropertyName("user_prompt_submit")]
public List<ExtendedHookEntryConfig> UserPromptSubmit { get; set; } = new();
// ── 도구 이벤트 ─────────────────────────────────────────────────────
[JsonPropertyName("pre_tool_use")]
public List<ExtendedHookEntryConfig> PreToolUse { get; set; } = new();
[JsonPropertyName("post_tool_use")]
public List<ExtendedHookEntryConfig> PostToolUse { get; set; } = new();
[JsonPropertyName("post_tool_use_failure")]
public List<ExtendedHookEntryConfig> PostToolUseFailure { get; set; } = new();
// ── 컨텍스트 압축 이벤트 ────────────────────────────────────────────
[JsonPropertyName("pre_compact")]
public List<ExtendedHookEntryConfig> PreCompact { get; set; } = new();
[JsonPropertyName("post_compact")]
public List<ExtendedHookEntryConfig> PostCompact { get; set; } = new();
// ── 파일·권한 이벤트 ────────────────────────────────────────────────
[JsonPropertyName("file_changed")]
public List<ExtendedHookEntryConfig> FileChanged { get; set; } = new();
[JsonPropertyName("session_start")]
public List<ExtendedHookEntryConfig> SessionStart { get; set; } = new();
[JsonPropertyName("session_end")]
public List<ExtendedHookEntryConfig> SessionEnd { get; set; } = new();
[JsonPropertyName("permission_request")]
public List<ExtendedHookEntryConfig> PermissionRequest { get; set; } = new();
}