claude-mpm 5.6.3__py3-none-any.whl → 5.6.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- claude_mpm/VERSION +1 -1
- claude_mpm/hooks/claude_hooks/__pycache__/__init__.cpython-311.pyc +0 -0
- claude_mpm/hooks/claude_hooks/__pycache__/__init__.cpython-314.pyc +0 -0
- claude_mpm/hooks/claude_hooks/__pycache__/auto_pause_handler.cpython-311.pyc +0 -0
- claude_mpm/hooks/claude_hooks/__pycache__/auto_pause_handler.cpython-314.pyc +0 -0
- claude_mpm/hooks/claude_hooks/__pycache__/correlation_manager.cpython-311.pyc +0 -0
- claude_mpm/hooks/claude_hooks/__pycache__/event_handlers.cpython-311.pyc +0 -0
- claude_mpm/hooks/claude_hooks/__pycache__/event_handlers.cpython-314.pyc +0 -0
- claude_mpm/hooks/claude_hooks/__pycache__/hook_handler.cpython-311.pyc +0 -0
- claude_mpm/hooks/claude_hooks/__pycache__/hook_handler.cpython-314.pyc +0 -0
- claude_mpm/hooks/claude_hooks/__pycache__/installer.cpython-314.pyc +0 -0
- claude_mpm/hooks/claude_hooks/__pycache__/memory_integration.cpython-311.pyc +0 -0
- claude_mpm/hooks/claude_hooks/__pycache__/memory_integration.cpython-314.pyc +0 -0
- claude_mpm/hooks/claude_hooks/__pycache__/response_tracking.cpython-311.pyc +0 -0
- claude_mpm/hooks/claude_hooks/__pycache__/response_tracking.cpython-314.pyc +0 -0
- claude_mpm/hooks/claude_hooks/__pycache__/tool_analysis.cpython-311.pyc +0 -0
- claude_mpm/hooks/claude_hooks/__pycache__/tool_analysis.cpython-314.pyc +0 -0
- claude_mpm/hooks/claude_hooks/auto_pause_handler.py +29 -30
- claude_mpm/hooks/claude_hooks/event_handlers.py +58 -105
- claude_mpm/hooks/claude_hooks/memory_integration.py +30 -21
- claude_mpm/hooks/claude_hooks/response_tracking.py +39 -58
- claude_mpm/hooks/claude_hooks/services/__pycache__/__init__.cpython-311.pyc +0 -0
- claude_mpm/hooks/claude_hooks/services/__pycache__/__init__.cpython-314.pyc +0 -0
- claude_mpm/hooks/claude_hooks/services/__pycache__/connection_manager_http.cpython-311.pyc +0 -0
- claude_mpm/hooks/claude_hooks/services/__pycache__/connection_manager_http.cpython-314.pyc +0 -0
- claude_mpm/hooks/claude_hooks/services/__pycache__/duplicate_detector.cpython-311.pyc +0 -0
- claude_mpm/hooks/claude_hooks/services/__pycache__/duplicate_detector.cpython-314.pyc +0 -0
- claude_mpm/hooks/claude_hooks/services/__pycache__/state_manager.cpython-311.pyc +0 -0
- claude_mpm/hooks/claude_hooks/services/__pycache__/state_manager.cpython-314.pyc +0 -0
- claude_mpm/hooks/claude_hooks/services/__pycache__/subagent_processor.cpython-311.pyc +0 -0
- claude_mpm/hooks/claude_hooks/services/__pycache__/subagent_processor.cpython-314.pyc +0 -0
- claude_mpm/hooks/claude_hooks/services/connection_manager.py +23 -28
- claude_mpm/hooks/claude_hooks/services/connection_manager_http.py +22 -26
- claude_mpm/hooks/claude_hooks/services/state_manager.py +23 -36
- claude_mpm/hooks/claude_hooks/services/subagent_processor.py +47 -73
- claude_mpm/hooks/session_resume_hook.py +22 -18
- claude_mpm/hooks/templates/pre_tool_use_template.py +10 -2
- {claude_mpm-5.6.3.dist-info → claude_mpm-5.6.5.dist-info}/METADATA +1 -1
- {claude_mpm-5.6.3.dist-info → claude_mpm-5.6.5.dist-info}/RECORD +44 -18
- {claude_mpm-5.6.3.dist-info → claude_mpm-5.6.5.dist-info}/WHEEL +0 -0
- {claude_mpm-5.6.3.dist-info → claude_mpm-5.6.5.dist-info}/entry_points.txt +0 -0
- {claude_mpm-5.6.3.dist-info → claude_mpm-5.6.5.dist-info}/licenses/LICENSE +0 -0
- {claude_mpm-5.6.3.dist-info → claude_mpm-5.6.5.dist-info}/licenses/LICENSE-FAQ.md +0 -0
- {claude_mpm-5.6.3.dist-info → claude_mpm-5.6.5.dist-info}/top_level.txt +0 -0
claude_mpm/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
5.6.
|
|
1
|
+
5.6.5
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -22,7 +22,7 @@ USAGE:
|
|
|
22
22
|
threshold_crossed = auto_pause.on_usage_update(metadata["usage"])
|
|
23
23
|
if threshold_crossed:
|
|
24
24
|
warning = auto_pause.emit_threshold_warning(threshold_crossed)
|
|
25
|
-
|
|
25
|
+
_log(f"\n⚠️ {warning}")
|
|
26
26
|
|
|
27
27
|
# Record actions during pause mode
|
|
28
28
|
if auto_pause.is_pause_active():
|
|
@@ -34,7 +34,6 @@ USAGE:
|
|
|
34
34
|
"""
|
|
35
35
|
|
|
36
36
|
import os
|
|
37
|
-
import sys
|
|
38
37
|
from datetime import datetime, timezone
|
|
39
38
|
from pathlib import Path
|
|
40
39
|
from typing import Any, Dict, Optional
|
|
@@ -45,6 +44,15 @@ from claude_mpm.services.infrastructure.context_usage_tracker import (
|
|
|
45
44
|
ContextUsageTracker,
|
|
46
45
|
)
|
|
47
46
|
|
|
47
|
+
# Try to import _log from hook_handler, fall back to no-op
|
|
48
|
+
try:
|
|
49
|
+
from claude_mpm.hooks.claude_hooks.hook_handler import _log
|
|
50
|
+
except ImportError:
|
|
51
|
+
|
|
52
|
+
def _log(msg: str) -> None:
|
|
53
|
+
pass # Silent fallback
|
|
54
|
+
|
|
55
|
+
|
|
48
56
|
logger = get_logger(__name__)
|
|
49
57
|
|
|
50
58
|
# Debug mode
|
|
@@ -100,11 +108,10 @@ class AutoPauseHandler:
|
|
|
100
108
|
self._previous_threshold = current_state.threshold_reached
|
|
101
109
|
|
|
102
110
|
if DEBUG:
|
|
103
|
-
|
|
111
|
+
_log(
|
|
104
112
|
f"AutoPauseHandler initialized: "
|
|
105
113
|
f"{current_state.percentage_used:.1f}% context used, "
|
|
106
|
-
f"threshold: {current_state.threshold_reached}"
|
|
107
|
-
file=sys.stderr,
|
|
114
|
+
f"threshold: {current_state.threshold_reached}"
|
|
108
115
|
)
|
|
109
116
|
except Exception as e:
|
|
110
117
|
logger.error(f"Failed to initialize AutoPauseHandler: {e}")
|
|
@@ -169,10 +176,9 @@ class AutoPauseHandler:
|
|
|
169
176
|
self._previous_threshold = current_threshold
|
|
170
177
|
|
|
171
178
|
if DEBUG:
|
|
172
|
-
|
|
179
|
+
_log(
|
|
173
180
|
f"Context threshold crossed: {current_threshold} "
|
|
174
|
-
f"({state.percentage_used:.1f}%)"
|
|
175
|
-
file=sys.stderr,
|
|
181
|
+
f"({state.percentage_used:.1f}%)"
|
|
176
182
|
)
|
|
177
183
|
|
|
178
184
|
# Trigger auto-pause if threshold reached
|
|
@@ -184,7 +190,7 @@ class AutoPauseHandler:
|
|
|
184
190
|
except Exception as e:
|
|
185
191
|
logger.error(f"Failed to update usage: {e}")
|
|
186
192
|
if DEBUG:
|
|
187
|
-
|
|
193
|
+
_log(f"❌ Usage update failed: {e}")
|
|
188
194
|
# Don't propagate error - auto-pause is optional
|
|
189
195
|
return None
|
|
190
196
|
|
|
@@ -220,12 +226,12 @@ class AutoPauseHandler:
|
|
|
220
226
|
)
|
|
221
227
|
|
|
222
228
|
if DEBUG:
|
|
223
|
-
|
|
229
|
+
_log(f"Recorded tool call during pause: {tool_name}")
|
|
224
230
|
|
|
225
231
|
except Exception as e:
|
|
226
232
|
logger.error(f"Failed to record tool call: {e}")
|
|
227
233
|
if DEBUG:
|
|
228
|
-
|
|
234
|
+
_log(f"❌ Failed to record tool call: {e}")
|
|
229
235
|
|
|
230
236
|
def on_assistant_response(self, response_summary: str) -> None:
|
|
231
237
|
"""Record an assistant response if auto-pause is active.
|
|
@@ -257,15 +263,14 @@ class AutoPauseHandler:
|
|
|
257
263
|
)
|
|
258
264
|
|
|
259
265
|
if DEBUG:
|
|
260
|
-
|
|
261
|
-
f"Recorded assistant response during pause (length: {len(summary)})"
|
|
262
|
-
file=sys.stderr,
|
|
266
|
+
_log(
|
|
267
|
+
f"Recorded assistant response during pause (length: {len(summary)})"
|
|
263
268
|
)
|
|
264
269
|
|
|
265
270
|
except Exception as e:
|
|
266
271
|
logger.error(f"Failed to record assistant response: {e}")
|
|
267
272
|
if DEBUG:
|
|
268
|
-
|
|
273
|
+
_log(f"❌ Failed to record assistant response: {e}")
|
|
269
274
|
|
|
270
275
|
def on_user_message(self, message_summary: str) -> None:
|
|
271
276
|
"""Record a user message if auto-pause is active.
|
|
@@ -297,15 +302,12 @@ class AutoPauseHandler:
|
|
|
297
302
|
)
|
|
298
303
|
|
|
299
304
|
if DEBUG:
|
|
300
|
-
|
|
301
|
-
f"Recorded user message during pause (length: {len(summary)})",
|
|
302
|
-
file=sys.stderr,
|
|
303
|
-
)
|
|
305
|
+
_log(f"Recorded user message during pause (length: {len(summary)})")
|
|
304
306
|
|
|
305
307
|
except Exception as e:
|
|
306
308
|
logger.error(f"Failed to record user message: {e}")
|
|
307
309
|
if DEBUG:
|
|
308
|
-
|
|
310
|
+
_log(f"❌ Failed to record user message: {e}")
|
|
309
311
|
|
|
310
312
|
def on_session_end(self) -> Optional[Path]:
|
|
311
313
|
"""Called when session ends. Finalizes any active pause.
|
|
@@ -318,7 +320,7 @@ class AutoPauseHandler:
|
|
|
318
320
|
"""
|
|
319
321
|
if not self.is_pause_active():
|
|
320
322
|
if DEBUG:
|
|
321
|
-
|
|
323
|
+
_log("No active pause to finalize")
|
|
322
324
|
return None
|
|
323
325
|
|
|
324
326
|
try:
|
|
@@ -326,14 +328,14 @@ class AutoPauseHandler:
|
|
|
326
328
|
session_path = self.pause_manager.finalize_pause(create_full_snapshot=True)
|
|
327
329
|
|
|
328
330
|
if session_path and DEBUG:
|
|
329
|
-
|
|
331
|
+
_log(f"✅ Session finalized: {session_path.name}")
|
|
330
332
|
|
|
331
333
|
return session_path
|
|
332
334
|
|
|
333
335
|
except Exception as e:
|
|
334
336
|
logger.error(f"Failed to finalize pause session: {e}")
|
|
335
337
|
if DEBUG:
|
|
336
|
-
|
|
338
|
+
_log(f"❌ Failed to finalize pause: {e}")
|
|
337
339
|
raise
|
|
338
340
|
|
|
339
341
|
def is_pause_active(self) -> bool:
|
|
@@ -417,9 +419,7 @@ class AutoPauseHandler:
|
|
|
417
419
|
# Check if pause is already active
|
|
418
420
|
if self.is_pause_active():
|
|
419
421
|
if DEBUG:
|
|
420
|
-
|
|
421
|
-
"Auto-pause already active, skipping trigger", file=sys.stderr
|
|
422
|
-
)
|
|
422
|
+
_log("Auto-pause already active, skipping trigger")
|
|
423
423
|
return
|
|
424
424
|
|
|
425
425
|
# Start incremental pause
|
|
@@ -429,16 +429,15 @@ class AutoPauseHandler:
|
|
|
429
429
|
)
|
|
430
430
|
|
|
431
431
|
if DEBUG:
|
|
432
|
-
|
|
432
|
+
_log(
|
|
433
433
|
f"✅ Auto-pause triggered: {session_id} "
|
|
434
|
-
f"({state.percentage_used:.1f}% context used)"
|
|
435
|
-
file=sys.stderr,
|
|
434
|
+
f"({state.percentage_used:.1f}% context used)"
|
|
436
435
|
)
|
|
437
436
|
|
|
438
437
|
except Exception as e:
|
|
439
438
|
logger.error(f"Failed to trigger auto-pause: {e}")
|
|
440
439
|
if DEBUG:
|
|
441
|
-
|
|
440
|
+
_log(f"❌ Failed to trigger auto-pause: {e}")
|
|
442
441
|
# Don't propagate - auto-pause is optional
|
|
443
442
|
|
|
444
443
|
def _summarize_dict(
|
|
@@ -8,12 +8,20 @@ Claude Code hook events.
|
|
|
8
8
|
import os
|
|
9
9
|
import re
|
|
10
10
|
import subprocess # nosec B404 - subprocess used for safe claude CLI version checking only
|
|
11
|
-
import sys
|
|
12
11
|
import uuid
|
|
13
12
|
from datetime import datetime, timezone
|
|
14
13
|
from pathlib import Path
|
|
15
14
|
from typing import Optional
|
|
16
15
|
|
|
16
|
+
# Import _log helper to avoid stderr writes (which cause hook errors)
|
|
17
|
+
try:
|
|
18
|
+
from .hook_handler import _log
|
|
19
|
+
except ImportError:
|
|
20
|
+
# Fallback for direct execution
|
|
21
|
+
def _log(message: str) -> None:
|
|
22
|
+
"""Fallback logger when hook_handler not available."""
|
|
23
|
+
|
|
24
|
+
|
|
17
25
|
# Import tool analysis with fallback for direct execution
|
|
18
26
|
try:
|
|
19
27
|
# Try relative import first (when imported as module)
|
|
@@ -34,8 +42,8 @@ except ImportError:
|
|
|
34
42
|
extract_tool_results,
|
|
35
43
|
)
|
|
36
44
|
|
|
37
|
-
# Debug mode
|
|
38
|
-
DEBUG = os.environ.get("CLAUDE_MPM_HOOK_DEBUG", "
|
|
45
|
+
# Debug mode - MUST match hook_handler.py default (false) to prevent stderr writes
|
|
46
|
+
DEBUG = os.environ.get("CLAUDE_MPM_HOOK_DEBUG", "false").lower() == "true"
|
|
39
47
|
|
|
40
48
|
# Import constants for configuration
|
|
41
49
|
try:
|
|
@@ -111,9 +119,8 @@ class EventHandlers:
|
|
|
111
119
|
"working_directory": working_dir,
|
|
112
120
|
}
|
|
113
121
|
if DEBUG:
|
|
114
|
-
|
|
115
|
-
f"Stored prompt for comprehensive tracking: session {session_id[:8]}..."
|
|
116
|
-
file=sys.stderr,
|
|
122
|
+
_log(
|
|
123
|
+
f"Stored prompt for comprehensive tracking: session {session_id[:8]}..."
|
|
117
124
|
)
|
|
118
125
|
except Exception: # nosec B110
|
|
119
126
|
# Response tracking is optional - silently continue if it fails
|
|
@@ -133,11 +140,8 @@ class EventHandlers:
|
|
|
133
140
|
# Enhanced debug logging for session correlation
|
|
134
141
|
session_id = event.get("session_id", "")
|
|
135
142
|
if DEBUG:
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
file=sys.stderr,
|
|
139
|
-
)
|
|
140
|
-
print(f" - event keys: {list(event.keys())}", file=sys.stderr)
|
|
143
|
+
_log(f" - session_id: {session_id[:16] if session_id else 'None'}...")
|
|
144
|
+
_log(f" - event keys: {list(event.keys())}")
|
|
141
145
|
|
|
142
146
|
tool_name = event.get("tool_name", "")
|
|
143
147
|
tool_input = event.get("tool_input", {})
|
|
@@ -180,9 +184,8 @@ class EventHandlers:
|
|
|
180
184
|
|
|
181
185
|
CorrelationManager.store(session_id, tool_call_id, tool_name)
|
|
182
186
|
if DEBUG:
|
|
183
|
-
|
|
184
|
-
f" - Generated tool_call_id: {tool_call_id[:8]}... for session {session_id[:8]}..."
|
|
185
|
-
file=sys.stderr,
|
|
187
|
+
_log(
|
|
188
|
+
f" - Generated tool_call_id: {tool_call_id[:8]}... for session {session_id[:8]}..."
|
|
186
189
|
)
|
|
187
190
|
|
|
188
191
|
# Add delegation-specific data if this is a Task tool
|
|
@@ -196,7 +199,7 @@ class EventHandlers:
|
|
|
196
199
|
auto_pause.on_tool_call(tool_name, tool_input)
|
|
197
200
|
except Exception as e:
|
|
198
201
|
if DEBUG:
|
|
199
|
-
|
|
202
|
+
_log(f"Auto-pause tool recording error: {e}")
|
|
200
203
|
|
|
201
204
|
self.hook_handler._emit_socketio_event("", "pre_tool", pre_tool_data)
|
|
202
205
|
|
|
@@ -212,9 +215,8 @@ class EventHandlers:
|
|
|
212
215
|
}
|
|
213
216
|
self.hook_handler._emit_socketio_event("", "todo_updated", todo_data)
|
|
214
217
|
if DEBUG:
|
|
215
|
-
|
|
216
|
-
f" - Emitted todo_updated event with {len(tool_params['todos'])} todos for session {session_id[:8]}..."
|
|
217
|
-
file=sys.stderr,
|
|
218
|
+
_log(
|
|
219
|
+
f" - Emitted todo_updated event with {len(tool_params['todos'])} todos for session {session_id[:8]}..."
|
|
218
220
|
)
|
|
219
221
|
|
|
220
222
|
def _handle_task_delegation(
|
|
@@ -255,12 +257,9 @@ class EventHandlers:
|
|
|
255
257
|
|
|
256
258
|
# Track this delegation for SubagentStop correlation and response tracking
|
|
257
259
|
if DEBUG:
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
)
|
|
262
|
-
print(f" - agent_type: {agent_type}", file=sys.stderr)
|
|
263
|
-
print(f" - raw_agent_type: {raw_agent_type}", file=sys.stderr)
|
|
260
|
+
_log(f" - session_id: {session_id[:16] if session_id else 'None'}...")
|
|
261
|
+
_log(f" - agent_type: {agent_type}")
|
|
262
|
+
_log(f" - raw_agent_type: {raw_agent_type}")
|
|
264
263
|
|
|
265
264
|
if session_id and agent_type != "unknown":
|
|
266
265
|
# Prepare request data for response tracking correlation
|
|
@@ -272,24 +271,17 @@ class EventHandlers:
|
|
|
272
271
|
self.hook_handler._track_delegation(session_id, agent_type, request_data)
|
|
273
272
|
|
|
274
273
|
if DEBUG:
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
f" - Request data keys: {list(request_data.keys())}",
|
|
278
|
-
file=sys.stderr,
|
|
279
|
-
)
|
|
274
|
+
_log(" - Delegation tracked successfully")
|
|
275
|
+
_log(f" - Request data keys: {list(request_data.keys())}")
|
|
280
276
|
delegation_requests = getattr(
|
|
281
277
|
self.hook_handler, "delegation_requests", {}
|
|
282
278
|
)
|
|
283
|
-
|
|
284
|
-
f" - delegation_requests size: {len(delegation_requests)}",
|
|
285
|
-
file=sys.stderr,
|
|
286
|
-
)
|
|
279
|
+
_log(f" - delegation_requests size: {len(delegation_requests)}")
|
|
287
280
|
|
|
288
281
|
# Log important delegations for debugging
|
|
289
282
|
if DEBUG or agent_type in ["research", "engineer", "qa", "documentation"]:
|
|
290
|
-
|
|
291
|
-
f"Hook handler: Task delegation started - agent: '{agent_type}', session: '{session_id}'"
|
|
292
|
-
file=sys.stderr,
|
|
283
|
+
_log(
|
|
284
|
+
f"Hook handler: Task delegation started - agent: '{agent_type}', session: '{session_id}'"
|
|
293
285
|
)
|
|
294
286
|
|
|
295
287
|
# Trigger memory pre-delegation hook
|
|
@@ -359,10 +351,10 @@ class EventHandlers:
|
|
|
359
351
|
)
|
|
360
352
|
|
|
361
353
|
if DEBUG:
|
|
362
|
-
|
|
354
|
+
_log(f" - Agent prompt logged for {agent_type}")
|
|
363
355
|
except Exception as e:
|
|
364
356
|
if DEBUG:
|
|
365
|
-
|
|
357
|
+
_log(f" - Could not log agent prompt: {e}")
|
|
366
358
|
|
|
367
359
|
def _get_git_branch(self, working_dir: Optional[str] = None) -> str:
|
|
368
360
|
"""Get git branch for the given directory with caching."""
|
|
@@ -450,9 +442,8 @@ class EventHandlers:
|
|
|
450
442
|
|
|
451
443
|
tool_call_id = CorrelationManager.retrieve(session_id) if session_id else None
|
|
452
444
|
if DEBUG and tool_call_id:
|
|
453
|
-
|
|
454
|
-
f" - Retrieved tool_call_id: {tool_call_id[:8]}... for session {session_id[:8]}..."
|
|
455
|
-
file=sys.stderr,
|
|
445
|
+
_log(
|
|
446
|
+
f" - Retrieved tool_call_id: {tool_call_id[:8]}... for session {session_id[:8]}..."
|
|
456
447
|
)
|
|
457
448
|
|
|
458
449
|
post_tool_data = {
|
|
@@ -605,16 +596,12 @@ class EventHandlers:
|
|
|
605
596
|
_log(f"⚠️ Auto-pause threshold crossed: {warning}")
|
|
606
597
|
|
|
607
598
|
if DEBUG:
|
|
608
|
-
|
|
609
|
-
f" - Auto-pause threshold crossed: {threshold_crossed}"
|
|
610
|
-
file=sys.stderr,
|
|
599
|
+
_log(
|
|
600
|
+
f" - Auto-pause threshold crossed: {threshold_crossed}"
|
|
611
601
|
)
|
|
612
602
|
except Exception as e:
|
|
613
603
|
if DEBUG:
|
|
614
|
-
|
|
615
|
-
f"Auto-pause error in handle_stop_fast: {e}",
|
|
616
|
-
file=sys.stderr,
|
|
617
|
-
)
|
|
604
|
+
_log(f"Auto-pause error in handle_stop_fast: {e}")
|
|
618
605
|
|
|
619
606
|
# Track response if enabled
|
|
620
607
|
try:
|
|
@@ -656,24 +643,15 @@ class EventHandlers:
|
|
|
656
643
|
getattr(rtm, "response_tracker", None) is not None if rtm else False
|
|
657
644
|
)
|
|
658
645
|
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
file=sys.stderr,
|
|
662
|
-
)
|
|
663
|
-
print(
|
|
664
|
-
f" - response_tracker exists: {tracker_exists}",
|
|
665
|
-
file=sys.stderr,
|
|
666
|
-
)
|
|
646
|
+
_log(f" - response_tracking_enabled: {tracking_enabled}")
|
|
647
|
+
_log(f" - response_tracker exists: {tracker_exists}")
|
|
667
648
|
except Exception: # nosec B110
|
|
668
649
|
# If debug logging fails, just skip it
|
|
669
650
|
pass
|
|
670
651
|
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
)
|
|
675
|
-
print(f" - reason: {metadata['reason']}", file=sys.stderr)
|
|
676
|
-
print(f" - stop_type: {metadata['stop_type']}", file=sys.stderr)
|
|
652
|
+
_log(f" - session_id: {session_id[:8] if session_id else 'None'}...")
|
|
653
|
+
_log(f" - reason: {metadata['reason']}")
|
|
654
|
+
_log(f" - stop_type: {metadata['stop_type']}")
|
|
677
655
|
|
|
678
656
|
def _emit_stop_event(self, event: dict, session_id: str, metadata: dict) -> None:
|
|
679
657
|
"""Emit stop event data to Socket.IO."""
|
|
@@ -735,10 +713,7 @@ class EventHandlers:
|
|
|
735
713
|
# If exact match fails, try partial matching
|
|
736
714
|
if not request_info and session_id:
|
|
737
715
|
if DEBUG:
|
|
738
|
-
|
|
739
|
-
f" - Trying fuzzy match for session {session_id[:16]}...",
|
|
740
|
-
file=sys.stderr,
|
|
741
|
-
)
|
|
716
|
+
_log(f" - Trying fuzzy match for session {session_id[:16]}...")
|
|
742
717
|
# Try to find a session that matches the first 8-16 characters
|
|
743
718
|
for stored_sid in list(delegation_requests.keys()):
|
|
744
719
|
if (
|
|
@@ -751,10 +726,7 @@ class EventHandlers:
|
|
|
751
726
|
)
|
|
752
727
|
):
|
|
753
728
|
if DEBUG:
|
|
754
|
-
|
|
755
|
-
f" - ✅ Fuzzy match found: {stored_sid[:16]}...",
|
|
756
|
-
file=sys.stderr,
|
|
757
|
-
)
|
|
729
|
+
_log(f" - ✅ Fuzzy match found: {stored_sid[:16]}...")
|
|
758
730
|
request_info = delegation_requests.get(stored_sid) # nosec B113
|
|
759
731
|
# Update the key to use the current session_id for consistency
|
|
760
732
|
if request_info:
|
|
@@ -823,9 +795,8 @@ class EventHandlers:
|
|
|
823
795
|
)
|
|
824
796
|
|
|
825
797
|
if file_path and DEBUG:
|
|
826
|
-
|
|
827
|
-
f"✅ Tracked {agent_type} agent response on SubagentStop: {file_path.name}"
|
|
828
|
-
file=sys.stderr,
|
|
798
|
+
_log(
|
|
799
|
+
f"✅ Tracked {agent_type} agent response on SubagentStop: {file_path.name}"
|
|
829
800
|
)
|
|
830
801
|
|
|
831
802
|
# Clean up the request data
|
|
@@ -836,16 +807,13 @@ class EventHandlers:
|
|
|
836
807
|
del delegation_requests[session_id]
|
|
837
808
|
|
|
838
809
|
elif DEBUG:
|
|
839
|
-
|
|
840
|
-
f"No request data for SubagentStop session {session_id[:8]}..., agent: {agent_type}"
|
|
841
|
-
file=sys.stderr,
|
|
810
|
+
_log(
|
|
811
|
+
f"No request data for SubagentStop session {session_id[:8]}..., agent: {agent_type}"
|
|
842
812
|
)
|
|
843
813
|
|
|
844
814
|
except Exception as e:
|
|
845
815
|
if DEBUG:
|
|
846
|
-
|
|
847
|
-
f"❌ Failed to track response on SubagentStop: {e}", file=sys.stderr
|
|
848
|
-
)
|
|
816
|
+
_log(f"❌ Failed to track response on SubagentStop: {e}")
|
|
849
817
|
|
|
850
818
|
def handle_assistant_response(self, event):
|
|
851
819
|
"""Handle assistant response events for comprehensive response tracking.
|
|
@@ -872,7 +840,7 @@ class EventHandlers:
|
|
|
872
840
|
self._scan_for_delegation_patterns(event)
|
|
873
841
|
except Exception as e: # nosec B110
|
|
874
842
|
if DEBUG:
|
|
875
|
-
|
|
843
|
+
_log(f"Delegation scanning error: {e}")
|
|
876
844
|
|
|
877
845
|
# Get working directory and git branch
|
|
878
846
|
working_dir = event.get("cwd", "")
|
|
@@ -921,9 +889,8 @@ class EventHandlers:
|
|
|
921
889
|
|
|
922
890
|
# Debug logging
|
|
923
891
|
if DEBUG:
|
|
924
|
-
|
|
925
|
-
f"Hook handler: Processing AssistantResponse - session: '{session_id}', response_length: {len(response_text)}"
|
|
926
|
-
file=sys.stderr,
|
|
892
|
+
_log(
|
|
893
|
+
f"Hook handler: Processing AssistantResponse - session: '{session_id}', response_length: {len(response_text)}"
|
|
927
894
|
)
|
|
928
895
|
|
|
929
896
|
# Record assistant response for auto-pause if active
|
|
@@ -939,7 +906,7 @@ class EventHandlers:
|
|
|
939
906
|
auto_pause.on_assistant_response(summary)
|
|
940
907
|
except Exception as e:
|
|
941
908
|
if DEBUG:
|
|
942
|
-
|
|
909
|
+
_log(f"Auto-pause response recording error: {e}")
|
|
943
910
|
|
|
944
911
|
# Emit normalized event
|
|
945
912
|
self.hook_handler._emit_socketio_event(
|
|
@@ -990,22 +957,13 @@ class EventHandlers:
|
|
|
990
957
|
if pending_todos:
|
|
991
958
|
session_start_data["pending_autotodos"] = pending_todos
|
|
992
959
|
session_start_data["autotodos_count"] = len(pending_todos)
|
|
993
|
-
|
|
994
|
-
print(
|
|
995
|
-
f" - Auto-injected {len(pending_todos)} pending autotodos",
|
|
996
|
-
file=sys.stderr,
|
|
997
|
-
)
|
|
960
|
+
_log(f" - Auto-injected {len(pending_todos)} pending autotodos")
|
|
998
961
|
except Exception as e: # nosec B110
|
|
999
962
|
# Auto-injection is optional - continue if it fails
|
|
1000
|
-
|
|
1001
|
-
print(f" - Failed to auto-inject autotodos: {e}", file=sys.stderr)
|
|
963
|
+
_log(f" - Failed to auto-inject autotodos: {e}")
|
|
1002
964
|
|
|
1003
965
|
# Debug logging
|
|
1004
|
-
|
|
1005
|
-
print(
|
|
1006
|
-
f"Hook handler: Processing SessionStart - session: '{session_id}'",
|
|
1007
|
-
file=sys.stderr,
|
|
1008
|
-
)
|
|
966
|
+
_log(f"Hook handler: Processing SessionStart - session: '{session_id}'")
|
|
1009
967
|
|
|
1010
968
|
# Emit normalized event
|
|
1011
969
|
self.hook_handler._emit_socketio_event("", "session_start", session_start_data)
|
|
@@ -1048,10 +1006,8 @@ class EventHandlers:
|
|
|
1048
1006
|
|
|
1049
1007
|
# Debug logging
|
|
1050
1008
|
if DEBUG:
|
|
1051
|
-
|
|
1052
|
-
f"Hook handler: SubagentStart - agent_type='{agent_type}', "
|
|
1053
|
-
f"agent_id='{agent_id}', session_id='{session_id[:16]}...'",
|
|
1054
|
-
file=sys.stderr,
|
|
1009
|
+
_log(
|
|
1010
|
+
f"Hook handler: SubagentStart - agent_type='{agent_type}', agent_id='{agent_id}', session_id='{session_id[:16]}...'"
|
|
1055
1011
|
)
|
|
1056
1012
|
|
|
1057
1013
|
# Emit to /hook namespace as subagent_start (NOT session_start!)
|
|
@@ -1086,7 +1042,7 @@ class EventHandlers:
|
|
|
1086
1042
|
from claude_mpm.services.event_log import get_event_log
|
|
1087
1043
|
except ImportError:
|
|
1088
1044
|
if DEBUG:
|
|
1089
|
-
|
|
1045
|
+
_log("Delegation detector or event log not available")
|
|
1090
1046
|
return
|
|
1091
1047
|
|
|
1092
1048
|
response_text = event.get("response", "")
|
|
@@ -1125,7 +1081,4 @@ class EventHandlers:
|
|
|
1125
1081
|
)
|
|
1126
1082
|
|
|
1127
1083
|
if DEBUG:
|
|
1128
|
-
|
|
1129
|
-
f"⚠️ PM violation detected: {detection['original_text'][:60]}...",
|
|
1130
|
-
file=sys.stderr,
|
|
1131
|
-
)
|
|
1084
|
+
_log(f"⚠️ PM violation detected: {detection['original_text'][:60]}...")
|