claude-mpm 4.5.6__py3-none-any.whl → 4.5.8__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/agents/BASE_OPS.md +10 -0
- claude_mpm/agents/PM_INSTRUCTIONS.md +28 -4
- claude_mpm/agents/templates/local_ops_agent.json +45 -9
- claude_mpm/services/async_session_logger.py +111 -95
- claude_mpm/services/claude_session_logger.py +61 -59
- claude_mpm/services/mcp_config_manager.py +186 -17
- claude_mpm/services/response_tracker.py +16 -5
- claude_mpm/services/session_manager.py +174 -0
- {claude_mpm-4.5.6.dist-info → claude_mpm-4.5.8.dist-info}/METADATA +1 -1
- {claude_mpm-4.5.6.dist-info → claude_mpm-4.5.8.dist-info}/RECORD +15 -14
- {claude_mpm-4.5.6.dist-info → claude_mpm-4.5.8.dist-info}/WHEEL +0 -0
- {claude_mpm-4.5.6.dist-info → claude_mpm-4.5.8.dist-info}/entry_points.txt +0 -0
- {claude_mpm-4.5.6.dist-info → claude_mpm-4.5.8.dist-info}/licenses/LICENSE +0 -0
- {claude_mpm-4.5.6.dist-info → claude_mpm-4.5.8.dist-info}/top_level.txt +0 -0
claude_mpm/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
4.5.
|
1
|
+
4.5.8
|
claude_mpm/agents/BASE_OPS.md
CHANGED
@@ -4,6 +4,16 @@ All Ops agents inherit these common operational patterns and requirements.
|
|
4
4
|
|
5
5
|
## Core Ops Principles
|
6
6
|
|
7
|
+
### Local Development Server Management
|
8
|
+
**CRITICAL IMPERATIVES FOR LOCAL-OPS AGENTS:**
|
9
|
+
- **MAINTAIN SINGLE STABLE INSTANCES**: Always strive to keep a single instance of each development server running stably. Avoid creating multiple instances of the same service.
|
10
|
+
- **NEVER INTERRUPT OTHER PROJECTS**: Before stopping ANY service, verify it's not being used by another project or Claude Code session. Check process ownership and working directories.
|
11
|
+
- **PROTECT CLAUDE CODE SERVICES**: Never terminate or interfere with Claude MPM services, monitor servers, or any processes that might be used by Claude Code.
|
12
|
+
- **PORT MANAGEMENT**: Always check if a port is in use before attempting to use it. If occupied, find an alternative rather than killing the existing process.
|
13
|
+
- **GRACEFUL OPERATIONS**: Use graceful shutdown procedures. Always attempt soft stops before forceful termination.
|
14
|
+
- **SESSION AWARENESS**: Be aware that multiple Claude Code sessions might be active. Coordinate rather than conflict.
|
15
|
+
- **HEALTH BEFORE ACTION**: Always verify service health before making changes. A running service should be left running unless explicitly requested to stop it.
|
16
|
+
|
7
17
|
### Infrastructure as Code
|
8
18
|
- All infrastructure must be version controlled
|
9
19
|
- Use declarative configuration over imperative scripts
|
@@ -164,9 +164,31 @@ Read: /mpm-doctor # WRONG - not a file to read
|
|
164
164
|
**User mentions error → PM delegates to Ops for logs (NEVER debugs)**
|
165
165
|
**User wants analysis → PM delegates to Code Analyzer (NEVER analyzes)**
|
166
166
|
|
167
|
+
### 🔥 LOCAL-OPS-AGENT PRIORITY RULE 🔥
|
168
|
+
|
169
|
+
**MANDATORY**: For ANY localhost/local development work, ALWAYS use **local-ops-agent** as the PRIMARY choice:
|
170
|
+
- **Local servers**: localhost:3000, dev servers → **local-ops-agent** (NOT generic Ops)
|
171
|
+
- **PM2 operations**: pm2 start/stop/status → **local-ops-agent** (EXPERT in PM2)
|
172
|
+
- **Port management**: Port conflicts, EADDRINUSE → **local-ops-agent** (HANDLES gracefully)
|
173
|
+
- **npm/yarn/pnpm**: npm start, yarn dev → **local-ops-agent** (PREFERRED)
|
174
|
+
- **Process management**: ps, kill, restart → **local-ops-agent** (SAFE operations)
|
175
|
+
- **Docker local**: docker-compose up → **local-ops-agent** (MANAGES containers)
|
176
|
+
|
177
|
+
**WHY local-ops-agent?**
|
178
|
+
- Maintains single stable instances (no duplicates)
|
179
|
+
- Never interrupts other projects or Claude Code
|
180
|
+
- Smart port allocation (finds alternatives, doesn't kill)
|
181
|
+
- Graceful operations (soft stops, proper cleanup)
|
182
|
+
- Session-aware (coordinates with multiple Claude sessions)
|
183
|
+
|
167
184
|
### Quick Delegation Matrix
|
168
185
|
| User Says | PM's IMMEDIATE Response | You MUST Delegate To |
|
169
186
|
|-----------|------------------------|---------------------|
|
187
|
+
| "localhost", "local server", "dev server" | "I'll delegate to local-ops agent" | **local-ops-agent** (PRIMARY) |
|
188
|
+
| "PM2", "process manager", "pm2 start" | "I'll have local-ops manage PM2" | **local-ops-agent** (ALWAYS) |
|
189
|
+
| "port 3000", "port conflict", "EADDRINUSE" | "I'll have local-ops handle ports" | **local-ops-agent** (EXPERT) |
|
190
|
+
| "npm start", "npm run dev", "yarn dev" | "I'll have local-ops run the dev server" | **local-ops-agent** (PREFERRED) |
|
191
|
+
| "start my app", "run locally" | "I'll delegate to local-ops agent" | **local-ops-agent** (DEFAULT) |
|
170
192
|
| "fix", "implement", "code", "create" | "I'll delegate this to Engineer" | Engineer |
|
171
193
|
| "test", "verify", "check" | "I'll have QA verify this" | QA (or web-qa/api-qa) |
|
172
194
|
| "deploy", "host", "launch" | "I'll delegate to Ops" | Ops (or platform-specific) |
|
@@ -245,7 +267,8 @@ START → [DELEGATE Research] → [DELEGATE Code Analyzer] → [DELEGATE Impleme
|
|
245
267
|
|
246
268
|
| Deployment Type | Ops Agent | Required Verifications |
|
247
269
|
|----------------|-----------|------------------------|
|
248
|
-
| Local Dev (PM2, Docker) |
|
270
|
+
| Local Dev (PM2, Docker) | **local-ops-agent** (PRIMARY) | Read logs, check process status, fetch endpoint, Playwright if UI |
|
271
|
+
| Local npm/yarn/pnpm | **local-ops-agent** (ALWAYS) | Process monitoring, port management, graceful operations |
|
249
272
|
| Vercel | vercel-ops-agent | Read build logs, fetch deployment URL, check function logs, Playwright for pages |
|
250
273
|
| Railway | railway-ops-agent | Read deployment logs, check health endpoint, verify database connections |
|
251
274
|
| GCP/Cloud Run | gcp-ops-agent | Check Cloud Run logs, verify service status, test endpoints |
|
@@ -274,9 +297,10 @@ Requirements:
|
|
274
297
|
## LOCAL DEPLOYMENT MANDATORY VERIFICATION
|
275
298
|
|
276
299
|
**CRITICAL**: PM MUST NEVER claim "running on localhost" without verification.
|
300
|
+
**PRIMARY AGENT**: Always use **local-ops-agent** for ALL localhost work.
|
277
301
|
|
278
302
|
### Required for ALL Local Deployments (PM2, Docker, npm start, etc.):
|
279
|
-
1. PM MUST delegate to local-ops-agent (
|
303
|
+
1. PM MUST delegate to **local-ops-agent** (NEVER generic Ops) for deployment
|
280
304
|
2. Ops agent MUST verify with ALL of these:
|
281
305
|
- Process status check (ps, pm2 status, docker ps)
|
282
306
|
- Log examination for startup errors
|
@@ -309,7 +333,7 @@ These phrases without fetch evidence = IMMEDIATE VIOLATION:
|
|
309
333
|
|------|-------------|----------|----------------|
|
310
334
|
| API | HTTP calls | curl/fetch output | web-qa (MANDATORY) |
|
311
335
|
| Web UI | Browser automation | Playwright results | web-qa with Playwright |
|
312
|
-
| Local Deploy | PM2/Docker status + fetch/Playwright | Logs + endpoint tests |
|
336
|
+
| Local Deploy | PM2/Docker status + fetch/Playwright | Logs + endpoint tests | **local-ops-agent** (MUST verify) |
|
313
337
|
| Vercel Deploy | Build success + fetch/Playwright | Deployment URL active | vercel-ops-agent (MUST verify) |
|
314
338
|
| Railway Deploy | Service healthy + fetch tests | Logs + endpoint response | railway-ops-agent (MUST verify) |
|
315
339
|
| GCP Deploy | Cloud Run active + endpoint tests | Service logs + HTTP 200 | gcp-ops-agent (MUST verify) |
|
@@ -597,7 +621,7 @@ Documentation → Report
|
|
597
621
|
- Web UI: Research → Analyzer → web-ui/react-engineer → Ops (deploy) → Ops (VERIFY with Playwright) → web-qa → Docs
|
598
622
|
- Vercel Site: Research → Analyzer → Engineer → vercel-ops (deploy) → vercel-ops (VERIFY) → web-qa → Docs
|
599
623
|
- Railway App: Research → Analyzer → Engineer → railway-ops (deploy) → railway-ops (VERIFY) → api-qa → Docs
|
600
|
-
- Local Dev: Research → Analyzer → Engineer →
|
624
|
+
- Local Dev: Research → Analyzer → Engineer → **local-ops-agent** (PM2/Docker) → **local-ops-agent** (VERIFY logs+fetch) → QA → Docs
|
601
625
|
- Bug Fix: Research → Analyzer → Engineer → Deploy → Ops (VERIFY) → web-qa (regression) → version-control
|
602
626
|
|
603
627
|
### Success Criteria
|
@@ -1,8 +1,8 @@
|
|
1
1
|
{
|
2
2
|
"name": "local-ops",
|
3
3
|
"display_name": "Local Operations Agent",
|
4
|
-
"description": "Specialized agent for managing local development deployments with
|
5
|
-
"version": "1.0.
|
4
|
+
"description": "Specialized agent for managing local development deployments with focus on maintaining single stable instances, protecting existing services, and never interfering with other projects or Claude Code services",
|
5
|
+
"version": "1.0.1",
|
6
6
|
"author": "Claude MPM",
|
7
7
|
"authority": {
|
8
8
|
"level": "deployment_manager",
|
@@ -65,7 +65,16 @@
|
|
65
65
|
"state_file": ".claude-mpm/deployment-state.json",
|
66
66
|
"health_check_interval": 30,
|
67
67
|
"auto_restart_attempts": 3,
|
68
|
-
"cleanup_on_exit": false
|
68
|
+
"cleanup_on_exit": false,
|
69
|
+
"stability_policy": {
|
70
|
+
"single_instance_enforcement": true,
|
71
|
+
"reuse_existing_processes": true,
|
72
|
+
"protect_external_services": true,
|
73
|
+
"avoid_port_conflicts": true,
|
74
|
+
"graceful_shutdown_timeout": 10000,
|
75
|
+
"check_process_ownership": true,
|
76
|
+
"preserve_claude_mpm_services": true
|
77
|
+
}
|
69
78
|
},
|
70
79
|
"commands": {
|
71
80
|
"deploy": {
|
@@ -78,9 +87,11 @@
|
|
78
87
|
"workflow": [
|
79
88
|
"detect_framework",
|
80
89
|
"check_existing_deployments",
|
81
|
-
"
|
90
|
+
"verify_no_conflicts",
|
91
|
+
"check_process_ownership",
|
92
|
+
"reuse_or_allocate_port",
|
82
93
|
"build_if_needed",
|
83
|
-
"
|
94
|
+
"start_or_attach_to_process",
|
84
95
|
"monitor_health",
|
85
96
|
"report_status"
|
86
97
|
]
|
@@ -213,7 +224,23 @@
|
|
213
224
|
"error_recovery": {
|
214
225
|
"port_conflict": {
|
215
226
|
"detection": "EADDRINUSE",
|
216
|
-
"action": "
|
227
|
+
"action": "check_process_owner_then_allocate_alternative_port",
|
228
|
+
"never": "kill_existing_process_without_verification"
|
229
|
+
},
|
230
|
+
"existing_service": {
|
231
|
+
"detection": "service_already_running",
|
232
|
+
"action": "attach_to_existing_or_report_status",
|
233
|
+
"never": "create_duplicate_instance"
|
234
|
+
},
|
235
|
+
"external_ownership": {
|
236
|
+
"detection": "process_owned_by_other_project",
|
237
|
+
"action": "allocate_different_resources",
|
238
|
+
"never": "interfere_with_external_process"
|
239
|
+
},
|
240
|
+
"claude_mpm_service": {
|
241
|
+
"detection": "claude-mpm|mcp|monitor",
|
242
|
+
"action": "report_status_only",
|
243
|
+
"never": "stop_or_restart_system_services"
|
217
244
|
},
|
218
245
|
"build_failure": {
|
219
246
|
"detection": "npm ERR!|ERROR|Failed",
|
@@ -235,11 +262,20 @@
|
|
235
262
|
"secrets_handling": "environment_variables"
|
236
263
|
},
|
237
264
|
"integration": {
|
265
|
+
"operational_principles": {
|
266
|
+
"single_instance_policy": "Always maintain single stable instances of services",
|
267
|
+
"non_interference": "Never interrupt services owned by other projects or Claude Code",
|
268
|
+
"service_protection": "Protect all Claude MPM, MCP, and monitor services",
|
269
|
+
"graceful_operations": "Always prefer graceful operations over forceful actions",
|
270
|
+
"conflict_avoidance": "Find alternative resources rather than stopping existing services"
|
271
|
+
},
|
238
272
|
"hooks": {
|
239
|
-
"pre_deploy": "
|
273
|
+
"pre_deploy": "check_conflicts_and_validate_requirements",
|
240
274
|
"post_deploy": "notify_status",
|
241
|
-
"pre_stop": "
|
242
|
-
"on_crash": "auto_restart_with_backoff"
|
275
|
+
"pre_stop": "verify_ownership_then_graceful_shutdown",
|
276
|
+
"on_crash": "auto_restart_with_backoff",
|
277
|
+
"before_port_use": "check_existing_process_owner",
|
278
|
+
"on_conflict": "find_alternative_resources"
|
243
279
|
},
|
244
280
|
"monitoring": {
|
245
281
|
"export_metrics": true,
|
@@ -31,6 +31,9 @@ from typing import Any, Dict, Optional
|
|
31
31
|
from claude_mpm.core.constants import PerformanceConfig, SystemLimits, TimeoutConfig
|
32
32
|
from claude_mpm.core.logging_utils import get_logger
|
33
33
|
|
34
|
+
# Import centralized session manager
|
35
|
+
from claude_mpm.services.session_manager import get_session_manager
|
36
|
+
|
34
37
|
# Import configuration manager
|
35
38
|
from ..core.config import Config
|
36
39
|
|
@@ -68,8 +71,13 @@ class AsyncSessionLogger:
|
|
68
71
|
- Configurable log formats (JSON, syslog, journald)
|
69
72
|
- Fire-and-forget pattern for zero latency impact
|
70
73
|
- Graceful degradation on errors
|
74
|
+
- Thread-safe singleton pattern with initialization flag
|
71
75
|
"""
|
72
76
|
|
77
|
+
_initialization_lock = Lock()
|
78
|
+
_initialized = False
|
79
|
+
_worker_started = False
|
80
|
+
|
73
81
|
def __init__(
|
74
82
|
self,
|
75
83
|
base_dir: Optional[Path] = None,
|
@@ -90,109 +98,108 @@ class AsyncSessionLogger:
|
|
90
98
|
enable_compression: Enable gzip compression for JSON logs (overrides config)
|
91
99
|
config: Configuration instance to use (creates new if not provided)
|
92
100
|
"""
|
93
|
-
#
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
# Get response logging configuration section
|
99
|
-
response_config = self.config.get("response_logging", {})
|
100
|
-
|
101
|
-
# Apply configuration with parameter overrides
|
102
|
-
self.base_dir = Path(
|
103
|
-
base_dir
|
104
|
-
or response_config.get("session_directory", ".claude-mpm/responses")
|
105
|
-
)
|
106
|
-
|
107
|
-
# Convert log format string to enum
|
108
|
-
format_str = response_config.get("format", "json").lower()
|
109
|
-
if log_format is not None:
|
110
|
-
self.log_format = log_format
|
111
|
-
elif format_str == "syslog":
|
112
|
-
self.log_format = LogFormat.SYSLOG
|
113
|
-
elif format_str == "journald":
|
114
|
-
self.log_format = LogFormat.JOURNALD
|
115
|
-
else:
|
116
|
-
self.log_format = LogFormat.JSON
|
117
|
-
|
118
|
-
self.max_queue_size = (
|
119
|
-
max_queue_size
|
120
|
-
if max_queue_size is not None
|
121
|
-
else response_config.get("max_queue_size", SystemLimits.MAX_QUEUE_SIZE)
|
122
|
-
)
|
123
|
-
|
124
|
-
# Handle async configuration with backward compatibility
|
125
|
-
if enable_async is not None:
|
126
|
-
self.enable_async = enable_async
|
127
|
-
else:
|
128
|
-
# Check configuration first, then environment variables for backward compatibility
|
129
|
-
self.enable_async = response_config.get("use_async", True)
|
130
|
-
# Override with environment variable if set (backward compatibility)
|
131
|
-
if os.environ.get("CLAUDE_USE_ASYNC_LOG"):
|
132
|
-
self.enable_async = (
|
133
|
-
os.environ.get("CLAUDE_USE_ASYNC_LOG", "true").lower() == "true"
|
134
|
-
)
|
135
|
-
|
136
|
-
# Check debug sync mode (forces synchronous for debugging)
|
137
|
-
if (
|
138
|
-
response_config.get("debug_sync", False)
|
139
|
-
or os.environ.get("CLAUDE_LOG_SYNC", "").lower() == "true"
|
140
|
-
):
|
141
|
-
logger.info("Debug sync mode enabled - forcing synchronous logging")
|
142
|
-
self.enable_async = False
|
143
|
-
|
144
|
-
self.enable_compression = (
|
145
|
-
enable_compression
|
146
|
-
if enable_compression is not None
|
147
|
-
else response_config.get("enable_compression", False)
|
148
|
-
)
|
101
|
+
# Use initialization flag to prevent duplicate setup
|
102
|
+
with self._initialization_lock:
|
103
|
+
if self._initialized and hasattr(self, "config"):
|
104
|
+
logger.debug("AsyncSessionLogger already initialized, skipping setup")
|
105
|
+
return
|
149
106
|
|
150
|
-
|
151
|
-
|
107
|
+
# Load configuration from YAML file or use provided config
|
108
|
+
if config is None:
|
109
|
+
config = Config()
|
110
|
+
self.config = config
|
152
111
|
|
153
|
-
|
154
|
-
|
112
|
+
# Get response logging configuration section
|
113
|
+
response_config = self.config.get("response_logging", {})
|
155
114
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
115
|
+
# Apply configuration with parameter overrides
|
116
|
+
self.base_dir = Path(
|
117
|
+
base_dir
|
118
|
+
or response_config.get("session_directory", ".claude-mpm/responses")
|
119
|
+
)
|
161
120
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
"
|
167
|
-
|
168
|
-
"
|
169
|
-
|
121
|
+
# Convert log format string to enum
|
122
|
+
format_str = response_config.get("format", "json").lower()
|
123
|
+
if log_format is not None:
|
124
|
+
self.log_format = log_format
|
125
|
+
elif format_str == "syslog":
|
126
|
+
self.log_format = LogFormat.SYSLOG
|
127
|
+
elif format_str == "journald":
|
128
|
+
self.log_format = LogFormat.JOURNALD
|
129
|
+
else:
|
130
|
+
self.log_format = LogFormat.JSON
|
170
131
|
|
171
|
-
|
172
|
-
|
132
|
+
self.max_queue_size = (
|
133
|
+
max_queue_size
|
134
|
+
if max_queue_size is not None
|
135
|
+
else response_config.get("max_queue_size", SystemLimits.MAX_QUEUE_SIZE)
|
136
|
+
)
|
173
137
|
|
174
|
-
|
175
|
-
|
176
|
-
|
138
|
+
# Handle async configuration with backward compatibility
|
139
|
+
if enable_async is not None:
|
140
|
+
self.enable_async = enable_async
|
141
|
+
else:
|
142
|
+
# Check configuration first, then environment variables for backward compatibility
|
143
|
+
self.enable_async = response_config.get("use_async", True)
|
144
|
+
# Override with environment variable if set (backward compatibility)
|
145
|
+
if os.environ.get("CLAUDE_USE_ASYNC_LOG"):
|
146
|
+
self.enable_async = (
|
147
|
+
os.environ.get("CLAUDE_USE_ASYNC_LOG", "true").lower() == "true"
|
148
|
+
)
|
177
149
|
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
150
|
+
# Check debug sync mode (forces synchronous for debugging)
|
151
|
+
if (
|
152
|
+
response_config.get("debug_sync", False)
|
153
|
+
or os.environ.get("CLAUDE_LOG_SYNC", "").lower() == "true"
|
154
|
+
):
|
155
|
+
logger.info("Debug sync mode enabled - forcing synchronous logging")
|
156
|
+
self.enable_async = False
|
157
|
+
|
158
|
+
self.enable_compression = (
|
159
|
+
enable_compression
|
160
|
+
if enable_compression is not None
|
161
|
+
else response_config.get("enable_compression", False)
|
162
|
+
)
|
182
163
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
164
|
+
# Create base directory
|
165
|
+
self.base_dir.mkdir(parents=True, exist_ok=True)
|
166
|
+
|
167
|
+
# Use centralized SessionManager for session ID
|
168
|
+
session_manager = get_session_manager()
|
169
|
+
self.session_id = session_manager.get_session_id()
|
170
|
+
|
171
|
+
# Async infrastructure
|
172
|
+
self._queue: Queue = Queue(maxsize=self.max_queue_size)
|
173
|
+
self._worker_thread: Optional[Thread] = None
|
174
|
+
self._shutdown = False
|
175
|
+
self._lock = Lock()
|
176
|
+
|
177
|
+
# Statistics
|
178
|
+
self.stats = {
|
179
|
+
"logged": 0,
|
180
|
+
"queued": 0,
|
181
|
+
"dropped": 0,
|
182
|
+
"errors": 0,
|
183
|
+
"avg_write_time_ms": 0.0,
|
184
|
+
}
|
185
|
+
|
186
|
+
# Initialize format-specific handlers
|
187
|
+
self._init_format_handler()
|
188
|
+
|
189
|
+
# Mark as initialized
|
190
|
+
self._initialized = True
|
191
|
+
|
192
|
+
# Log initialization status
|
193
|
+
logger.info(
|
194
|
+
f"AsyncSessionLogger initialized with SessionManager: session_id={self.session_id}, async={self.enable_async}, format={self.log_format.value}"
|
195
|
+
)
|
191
196
|
|
192
|
-
#
|
193
|
-
|
194
|
-
|
195
|
-
|
197
|
+
# Start background worker if async enabled (outside initialization lock)
|
198
|
+
if self.enable_async and not self._worker_started:
|
199
|
+
with self._initialization_lock:
|
200
|
+
if not self._worker_started:
|
201
|
+
self._start_worker()
|
202
|
+
self._worker_started = True
|
196
203
|
|
197
204
|
def _init_format_handler(self):
|
198
205
|
"""Initialize format-specific logging handlers."""
|
@@ -519,8 +526,17 @@ class AsyncSessionLogger:
|
|
519
526
|
return self.stats.copy()
|
520
527
|
|
521
528
|
def set_session_id(self, session_id: str):
|
522
|
-
"""Set a new session ID.
|
529
|
+
"""Set a new session ID.
|
530
|
+
|
531
|
+
Note: This updates both the local session ID and the SessionManager.
|
532
|
+
|
533
|
+
Args:
|
534
|
+
session_id: The new session ID to use
|
535
|
+
"""
|
523
536
|
self.session_id = session_id
|
537
|
+
# Also update SessionManager to keep consistency
|
538
|
+
session_manager = get_session_manager()
|
539
|
+
session_manager.set_session_id(session_id)
|
524
540
|
logger.info(f"Session ID updated to: {session_id}")
|
525
541
|
|
526
542
|
def is_enabled(self) -> bool:
|
@@ -13,11 +13,15 @@ Configuration via .claude-mpm/configuration.yaml.
|
|
13
13
|
import json
|
14
14
|
import os
|
15
15
|
from datetime import datetime, timezone
|
16
|
+
from threading import Lock
|
16
17
|
from typing import Any, Dict, Optional
|
17
18
|
|
18
19
|
# Import configuration manager
|
19
20
|
from claude_mpm.core.config import Config
|
20
21
|
|
22
|
+
# Import centralized session manager
|
23
|
+
from claude_mpm.services.session_manager import get_session_manager
|
24
|
+
|
21
25
|
# Try to import async logger for performance optimization
|
22
26
|
try:
|
23
27
|
from claude_mpm.services.async_session_logger import (
|
@@ -38,6 +42,9 @@ logger = get_logger(__name__)
|
|
38
42
|
class ClaudeSessionLogger:
|
39
43
|
"""Simplified response logger for Claude Code sessions."""
|
40
44
|
|
45
|
+
_initialization_lock = Lock()
|
46
|
+
_initialized = False
|
47
|
+
|
41
48
|
def __init__(
|
42
49
|
self,
|
43
50
|
base_dir: Optional[Path] = None,
|
@@ -52,29 +59,41 @@ class ClaudeSessionLogger:
|
|
52
59
|
use_async: Use async logging if available. Overrides config.
|
53
60
|
config: Configuration instance to use (creates new if not provided)
|
54
61
|
"""
|
55
|
-
#
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
base_dir
|
71
|
-
|
72
|
-
|
73
|
-
|
62
|
+
# Use initialization flag to prevent duplicate setup
|
63
|
+
with self._initialization_lock:
|
64
|
+
if self._initialized and hasattr(self, "config"):
|
65
|
+
logger.debug("ClaudeSessionLogger already initialized, skipping setup")
|
66
|
+
return
|
67
|
+
|
68
|
+
# Load configuration
|
69
|
+
if config is None:
|
70
|
+
config = Config()
|
71
|
+
self.config = config
|
72
|
+
|
73
|
+
# Get response logging configuration
|
74
|
+
response_config = self.config.get("response_logging", {})
|
75
|
+
|
76
|
+
# Determine base directory
|
77
|
+
if base_dir is None:
|
78
|
+
# Check configuration first
|
79
|
+
base_dir = response_config.get("session_directory")
|
80
|
+
if not base_dir:
|
81
|
+
# Fall back to default response directory
|
82
|
+
base_dir = ".claude-mpm/responses"
|
83
|
+
base_dir = Path(base_dir)
|
84
|
+
|
85
|
+
self.base_dir = Path(base_dir)
|
86
|
+
self.base_dir.mkdir(parents=True, exist_ok=True)
|
87
|
+
|
88
|
+
# Use centralized SessionManager for session ID
|
89
|
+
session_manager = get_session_manager()
|
90
|
+
self.session_id = session_manager.get_session_id()
|
91
|
+
logger.info(
|
92
|
+
f"ClaudeSessionLogger using session ID from SessionManager: {self.session_id}"
|
93
|
+
)
|
74
94
|
|
75
|
-
|
76
|
-
|
77
|
-
self.response_counter = {} # Track response count per session
|
95
|
+
self.response_counter = {} # Track response count per session
|
96
|
+
self._initialized = True
|
78
97
|
|
79
98
|
# Determine if we should use async logging
|
80
99
|
if use_async is None:
|
@@ -117,38 +136,6 @@ class ClaudeSessionLogger:
|
|
117
136
|
)
|
118
137
|
self.use_async = False
|
119
138
|
|
120
|
-
def _get_claude_session_id(self) -> Optional[str]:
|
121
|
-
"""
|
122
|
-
Get the Claude Code session ID from environment.
|
123
|
-
|
124
|
-
Returns:
|
125
|
-
Session ID if available, None otherwise
|
126
|
-
"""
|
127
|
-
# Claude Code may set various environment variables
|
128
|
-
# Check common patterns
|
129
|
-
session_id = None
|
130
|
-
|
131
|
-
# Check for CLAUDE_SESSION_ID
|
132
|
-
session_id = os.environ.get("CLAUDE_SESSION_ID")
|
133
|
-
|
134
|
-
# Check for ANTHROPIC_SESSION_ID
|
135
|
-
if not session_id:
|
136
|
-
session_id = os.environ.get("ANTHROPIC_SESSION_ID")
|
137
|
-
|
138
|
-
# Check for generic SESSION_ID
|
139
|
-
if not session_id:
|
140
|
-
session_id = os.environ.get("SESSION_ID")
|
141
|
-
|
142
|
-
# Generate a default based on timestamp if nothing found
|
143
|
-
if not session_id:
|
144
|
-
# Use a timestamp-based session ID as fallback
|
145
|
-
session_id = datetime.now(timezone.utc).strftime("%Y%m%d_%H%M%S")
|
146
|
-
logger.info(f"Session ID: {session_id} (generated)")
|
147
|
-
else:
|
148
|
-
logger.info(f"Session ID: {session_id}")
|
149
|
-
|
150
|
-
return session_id
|
151
|
-
|
152
139
|
def _generate_filename(self, agent: Optional[str] = None) -> str:
|
153
140
|
"""
|
154
141
|
Generate a flat filename with session ID, agent, and timestamp.
|
@@ -251,10 +238,15 @@ class ClaudeSessionLogger:
|
|
251
238
|
"""
|
252
239
|
Manually set the session ID.
|
253
240
|
|
241
|
+
Note: This updates both the local session ID and the SessionManager.
|
242
|
+
|
254
243
|
Args:
|
255
244
|
session_id: The session ID to use
|
256
245
|
"""
|
257
246
|
self.session_id = session_id
|
247
|
+
# Also update SessionManager to keep consistency
|
248
|
+
session_manager = get_session_manager()
|
249
|
+
session_manager.set_session_id(session_id)
|
258
250
|
logger.info(f"Session ID set to: {session_id}")
|
259
251
|
|
260
252
|
def get_session_path(self) -> Optional[Path]:
|
@@ -280,13 +272,16 @@ class ClaudeSessionLogger:
|
|
280
272
|
return self.session_id is not None
|
281
273
|
|
282
274
|
|
283
|
-
# Singleton instance
|
275
|
+
# Singleton instance with thread-safe initialization
|
284
276
|
_logger_instance = None
|
277
|
+
_logger_lock = Lock()
|
285
278
|
|
286
279
|
|
287
280
|
def get_session_logger(config: Optional[Config] = None) -> ClaudeSessionLogger:
|
288
281
|
"""
|
289
|
-
Get the singleton session logger instance.
|
282
|
+
Get the singleton session logger instance with thread-safe initialization.
|
283
|
+
|
284
|
+
Uses double-checked locking pattern to ensure thread safety.
|
290
285
|
|
291
286
|
Args:
|
292
287
|
config: Optional configuration instance to use
|
@@ -295,9 +290,16 @@ def get_session_logger(config: Optional[Config] = None) -> ClaudeSessionLogger:
|
|
295
290
|
The shared ClaudeSessionLogger instance
|
296
291
|
"""
|
297
292
|
global _logger_instance
|
298
|
-
|
299
|
-
|
300
|
-
|
293
|
+
|
294
|
+
# Fast path - check without lock
|
295
|
+
if _logger_instance is not None:
|
296
|
+
return _logger_instance
|
297
|
+
|
298
|
+
# Slow path - acquire lock and double-check
|
299
|
+
with _logger_lock:
|
300
|
+
if _logger_instance is None:
|
301
|
+
_logger_instance = ClaudeSessionLogger(config=config)
|
302
|
+
return _logger_instance
|
301
303
|
|
302
304
|
|
303
305
|
def log_response(
|
@@ -41,6 +41,14 @@ class MCPConfigManager:
|
|
41
41
|
"kuzu-memory",
|
42
42
|
}
|
43
43
|
|
44
|
+
# Known missing dependencies for MCP services that pipx doesn't handle automatically
|
45
|
+
# Maps service names to list of missing dependencies that need injection
|
46
|
+
SERVICE_MISSING_DEPENDENCIES = {
|
47
|
+
"mcp-ticketer": ["gql"], # mcp-ticketer v0.1.8+ needs gql but doesn't declare it
|
48
|
+
# Add more services here as needed, e.g.:
|
49
|
+
# "another-service": ["dep1", "dep2"],
|
50
|
+
}
|
51
|
+
|
44
52
|
# Static known-good MCP service configurations
|
45
53
|
# These are the correct, tested configurations that work reliably
|
46
54
|
# Note: Commands will be resolved to full paths dynamically in get_static_service_config()
|
@@ -943,6 +951,11 @@ class MCPConfigManager:
|
|
943
951
|
)
|
944
952
|
|
945
953
|
if result.returncode == 0:
|
954
|
+
# Inject any missing dependencies if needed
|
955
|
+
if service_name in self.SERVICE_MISSING_DEPENDENCIES:
|
956
|
+
self.logger.debug(f"Injecting missing dependencies for newly installed {service_name}...")
|
957
|
+
self._inject_missing_dependencies(service_name)
|
958
|
+
|
946
959
|
# Verify installation worked
|
947
960
|
if self._verify_service_installed(service_name, "pipx"):
|
948
961
|
return True, "pipx"
|
@@ -1092,18 +1105,39 @@ class MCPConfigManager:
|
|
1092
1105
|
failed_services.append(f"{service_name} (reinstall failed)")
|
1093
1106
|
|
1094
1107
|
elif issue_type == "missing_dependency":
|
1095
|
-
# Fix missing dependencies
|
1108
|
+
# Fix missing dependencies - try injection first, then reinstall if needed
|
1096
1109
|
self.logger.info(
|
1097
|
-
f" {service_name} has missing dependencies -
|
1110
|
+
f" {service_name} has missing dependencies - attempting fix..."
|
1098
1111
|
)
|
1112
|
+
|
1113
|
+
# First try to inject dependencies without reinstalling
|
1114
|
+
injection_success = self._inject_missing_dependencies(service_name)
|
1115
|
+
|
1116
|
+
if injection_success:
|
1117
|
+
# Verify the fix worked
|
1118
|
+
issue_after_injection = self._detect_service_issue(service_name)
|
1119
|
+
if issue_after_injection is None:
|
1120
|
+
fixed_services.append(f"{service_name} (dependencies injected)")
|
1121
|
+
self.logger.info(f" ✅ Fixed {service_name} with dependency injection")
|
1122
|
+
continue # Move to next service
|
1123
|
+
|
1124
|
+
# If injection alone didn't work, try full reinstall
|
1125
|
+
self.logger.info(" Dependency injection insufficient, trying full reinstall...")
|
1099
1126
|
success = self._auto_reinstall_mcp_service(service_name)
|
1100
1127
|
if success:
|
1101
|
-
fixed_services.append(f"{service_name} (auto-reinstalled)")
|
1128
|
+
fixed_services.append(f"{service_name} (auto-reinstalled with dependencies)")
|
1102
1129
|
else:
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1130
|
+
# Provide specific manual fix for known services
|
1131
|
+
if service_name == "mcp-ticketer":
|
1132
|
+
self.logger.warning(
|
1133
|
+
f" Auto-fix failed for {service_name}. Manual fix: "
|
1134
|
+
f"pipx uninstall {service_name} && pipx install {service_name} && pipx inject {service_name} gql"
|
1135
|
+
)
|
1136
|
+
else:
|
1137
|
+
self.logger.warning(
|
1138
|
+
f" Auto-reinstall failed for {service_name}. Manual fix: "
|
1139
|
+
f"pipx uninstall {service_name} && pipx install {service_name}"
|
1140
|
+
)
|
1107
1141
|
failed_services.append(f"{service_name} (auto-reinstall failed)")
|
1108
1142
|
|
1109
1143
|
elif issue_type == "path_issue":
|
@@ -1129,7 +1163,11 @@ class MCPConfigManager:
|
|
1129
1163
|
message += "\n\n💡 Manual fix instructions:"
|
1130
1164
|
for failed in failed_services:
|
1131
1165
|
service = failed.split(" ")[0]
|
1132
|
-
|
1166
|
+
if service in self.SERVICE_MISSING_DEPENDENCIES:
|
1167
|
+
deps = " ".join([f"&& pipx inject {service} {dep}" for dep in self.SERVICE_MISSING_DEPENDENCIES[service]])
|
1168
|
+
message += f"\n • {service}: pipx uninstall {service} && pipx install {service} {deps}"
|
1169
|
+
else:
|
1170
|
+
message += f"\n • {service}: pipx uninstall {service} && pipx install {service}"
|
1133
1171
|
|
1134
1172
|
return success, message
|
1135
1173
|
|
@@ -1148,7 +1186,58 @@ class MCPConfigManager:
|
|
1148
1186
|
|
1149
1187
|
# Try to run the service with --help to detect issues
|
1150
1188
|
try:
|
1151
|
-
#
|
1189
|
+
# First check if service is installed in pipx venv
|
1190
|
+
pipx_venv_bin = self.pipx_base / service_name / "bin" / service_name
|
1191
|
+
if pipx_venv_bin.exists():
|
1192
|
+
# Test the installed version directly (has injected dependencies)
|
1193
|
+
# This avoids using pipx run which downloads a fresh cache copy without dependencies
|
1194
|
+
self.logger.debug(f"Testing {service_name} from installed pipx venv: {pipx_venv_bin}")
|
1195
|
+
result = subprocess.run(
|
1196
|
+
[str(pipx_venv_bin), "--help"],
|
1197
|
+
capture_output=True,
|
1198
|
+
text=True,
|
1199
|
+
timeout=10,
|
1200
|
+
check=False,
|
1201
|
+
)
|
1202
|
+
|
1203
|
+
# Check for specific error patterns in installed version
|
1204
|
+
stderr_lower = result.stderr.lower()
|
1205
|
+
stdout_lower = result.stdout.lower()
|
1206
|
+
combined_output = stderr_lower + stdout_lower
|
1207
|
+
|
1208
|
+
# Import errors in installed version (should be rare if dependencies injected)
|
1209
|
+
if (
|
1210
|
+
"modulenotfounderror" in combined_output
|
1211
|
+
or "importerror" in combined_output
|
1212
|
+
):
|
1213
|
+
# Check if it's specifically the gql dependency for mcp-ticketer
|
1214
|
+
if service_name == "mcp-ticketer" and "gql" in combined_output:
|
1215
|
+
return "missing_dependency"
|
1216
|
+
return "import_error"
|
1217
|
+
|
1218
|
+
# Path issues
|
1219
|
+
if "no such file or directory" in combined_output:
|
1220
|
+
return "path_issue"
|
1221
|
+
|
1222
|
+
# If help text appears, service is working
|
1223
|
+
if (
|
1224
|
+
"usage:" in combined_output
|
1225
|
+
or "help" in combined_output
|
1226
|
+
or result.returncode in [0, 1]
|
1227
|
+
):
|
1228
|
+
self.logger.debug(f"{service_name} is working correctly")
|
1229
|
+
return None # Service is working
|
1230
|
+
|
1231
|
+
# Unknown issue
|
1232
|
+
if result.returncode not in [0, 1]:
|
1233
|
+
self.logger.debug(f"{service_name} returned unexpected exit code: {result.returncode}")
|
1234
|
+
return "unknown_error"
|
1235
|
+
|
1236
|
+
return None # Default to working if no issues detected
|
1237
|
+
|
1238
|
+
# Service not installed in pipx venv - use pipx run for detection
|
1239
|
+
# Note: pipx run uses cache which may not have injected dependencies
|
1240
|
+
self.logger.debug(f"Testing {service_name} via pipx run (not installed in venv)")
|
1152
1241
|
result = subprocess.run(
|
1153
1242
|
["pipx", "run", service_name, "--help"],
|
1154
1243
|
capture_output=True,
|
@@ -1169,15 +1258,15 @@ class MCPConfigManager:
|
|
1169
1258
|
):
|
1170
1259
|
return "not_installed"
|
1171
1260
|
|
1172
|
-
# Import errors
|
1261
|
+
# Import errors when using pipx run (cache version)
|
1173
1262
|
if (
|
1174
1263
|
"modulenotfounderror" in combined_output
|
1175
1264
|
or "importerror" in combined_output
|
1176
1265
|
):
|
1177
|
-
#
|
1178
|
-
|
1179
|
-
|
1180
|
-
return "
|
1266
|
+
# Don't report missing_dependency for cache version - it may be missing injected deps
|
1267
|
+
# Just report that service needs to be installed properly
|
1268
|
+
self.logger.debug(f"{service_name} has import errors in pipx run cache - needs proper installation")
|
1269
|
+
return "not_installed"
|
1181
1270
|
|
1182
1271
|
# Path issues
|
1183
1272
|
if "no such file or directory" in combined_output:
|
@@ -1240,6 +1329,11 @@ class MCPConfigManager:
|
|
1240
1329
|
)
|
1241
1330
|
|
1242
1331
|
if install_result.returncode == 0:
|
1332
|
+
# Inject any missing dependencies if needed
|
1333
|
+
if service_name in self.SERVICE_MISSING_DEPENDENCIES:
|
1334
|
+
self.logger.debug(f"Injecting missing dependencies for {service_name}...")
|
1335
|
+
self._inject_missing_dependencies(service_name)
|
1336
|
+
|
1243
1337
|
# Verify the reinstall worked
|
1244
1338
|
issue = self._detect_service_issue(service_name)
|
1245
1339
|
if issue is None:
|
@@ -1258,6 +1352,65 @@ class MCPConfigManager:
|
|
1258
1352
|
self.logger.error(f"Error reinstalling {service_name}: {e}")
|
1259
1353
|
return False
|
1260
1354
|
|
1355
|
+
def _inject_missing_dependencies(self, service_name: str) -> bool:
|
1356
|
+
"""
|
1357
|
+
Inject missing dependencies into a pipx-installed MCP service.
|
1358
|
+
|
1359
|
+
Some MCP services don't properly declare all their dependencies in their
|
1360
|
+
package metadata, which causes import errors when pipx creates isolated
|
1361
|
+
virtual environments. This method injects the missing dependencies using
|
1362
|
+
pipx inject.
|
1363
|
+
|
1364
|
+
Args:
|
1365
|
+
service_name: Name of the MCP service to fix
|
1366
|
+
|
1367
|
+
Returns:
|
1368
|
+
True if dependencies were injected successfully or no injection needed, False otherwise
|
1369
|
+
"""
|
1370
|
+
# Check if this service has known missing dependencies
|
1371
|
+
if service_name not in self.SERVICE_MISSING_DEPENDENCIES:
|
1372
|
+
return True # No dependencies to inject
|
1373
|
+
|
1374
|
+
missing_deps = self.SERVICE_MISSING_DEPENDENCIES[service_name]
|
1375
|
+
if not missing_deps:
|
1376
|
+
return True # No dependencies to inject
|
1377
|
+
|
1378
|
+
self.logger.info(
|
1379
|
+
f" → Injecting missing dependencies for {service_name}: {', '.join(missing_deps)}"
|
1380
|
+
)
|
1381
|
+
|
1382
|
+
all_successful = True
|
1383
|
+
for dep in missing_deps:
|
1384
|
+
try:
|
1385
|
+
self.logger.debug(f" Injecting {dep} into {service_name}...")
|
1386
|
+
result = subprocess.run(
|
1387
|
+
["pipx", "inject", service_name, dep],
|
1388
|
+
capture_output=True,
|
1389
|
+
text=True,
|
1390
|
+
timeout=60,
|
1391
|
+
check=False,
|
1392
|
+
)
|
1393
|
+
|
1394
|
+
if result.returncode == 0:
|
1395
|
+
self.logger.info(f" ✅ Successfully injected {dep}")
|
1396
|
+
# Check if already injected (pipx will complain if package already exists)
|
1397
|
+
elif "already satisfied" in result.stderr.lower() or "already installed" in result.stderr.lower():
|
1398
|
+
self.logger.debug(f" {dep} already present in {service_name}")
|
1399
|
+
else:
|
1400
|
+
self.logger.error(
|
1401
|
+
f" Failed to inject {dep}: {result.stderr}"
|
1402
|
+
)
|
1403
|
+
all_successful = False
|
1404
|
+
|
1405
|
+
except subprocess.TimeoutExpired:
|
1406
|
+
self.logger.error(f" Timeout while injecting {dep}")
|
1407
|
+
all_successful = False
|
1408
|
+
except Exception as e:
|
1409
|
+
self.logger.error(f" Error injecting {dep}: {e}")
|
1410
|
+
all_successful = False
|
1411
|
+
|
1412
|
+
return all_successful
|
1413
|
+
|
1261
1414
|
def _auto_reinstall_mcp_service(self, service_name: str) -> bool:
|
1262
1415
|
"""
|
1263
1416
|
Automatically reinstall an MCP service with missing dependencies.
|
@@ -1312,6 +1465,14 @@ class MCPConfigManager:
|
|
1312
1465
|
)
|
1313
1466
|
return False
|
1314
1467
|
|
1468
|
+
# Inject any missing dependencies that pipx doesn't handle automatically
|
1469
|
+
if service_name in self.SERVICE_MISSING_DEPENDENCIES:
|
1470
|
+
self.logger.info(f" → Fixing missing dependencies for {service_name}...")
|
1471
|
+
if not self._inject_missing_dependencies(service_name):
|
1472
|
+
self.logger.warning(
|
1473
|
+
f"Failed to inject all dependencies for {service_name}, but continuing..."
|
1474
|
+
)
|
1475
|
+
|
1315
1476
|
# Verify the reinstall worked
|
1316
1477
|
self.logger.info(f" → Verifying {service_name} installation...")
|
1317
1478
|
issue = self._detect_service_issue(service_name)
|
@@ -1319,9 +1480,17 @@ class MCPConfigManager:
|
|
1319
1480
|
if issue is None:
|
1320
1481
|
self.logger.info(f" ✅ Successfully reinstalled {service_name}")
|
1321
1482
|
return True
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1483
|
+
|
1484
|
+
# If still has missing dependency issue after injection, log specific instructions
|
1485
|
+
if issue == "missing_dependency" and service_name == "mcp-ticketer":
|
1486
|
+
self.logger.error(
|
1487
|
+
f" {service_name} still has missing dependencies after injection. "
|
1488
|
+
f"Manual fix: pipx inject {service_name} gql"
|
1489
|
+
)
|
1490
|
+
else:
|
1491
|
+
self.logger.warning(
|
1492
|
+
f"Reinstalled {service_name} but still has issue: {issue}"
|
1493
|
+
)
|
1325
1494
|
return False
|
1326
1495
|
|
1327
1496
|
except subprocess.TimeoutExpired:
|
@@ -19,6 +19,7 @@ DESIGN DECISIONS:
|
|
19
19
|
"""
|
20
20
|
|
21
21
|
from datetime import datetime, timezone
|
22
|
+
from threading import Lock
|
22
23
|
from typing import Any, Dict, Optional
|
23
24
|
|
24
25
|
from claude_mpm.core.config import Config
|
@@ -214,12 +215,15 @@ class ResponseTracker:
|
|
214
215
|
logger.info(f"Response tracker session ID set to: {session_id}")
|
215
216
|
|
216
217
|
|
217
|
-
# Singleton instance
|
218
|
+
# Singleton instance with thread-safe initialization
|
218
219
|
_tracker_instance = None
|
220
|
+
_tracker_lock = Lock()
|
219
221
|
|
220
222
|
|
221
223
|
def get_response_tracker(config: Optional[Config] = None) -> ResponseTracker:
|
222
|
-
"""Get the singleton response tracker instance.
|
224
|
+
"""Get the singleton response tracker instance with thread-safe initialization.
|
225
|
+
|
226
|
+
Uses double-checked locking pattern to ensure thread safety.
|
223
227
|
|
224
228
|
Args:
|
225
229
|
config: Optional configuration instance
|
@@ -228,9 +232,16 @@ def get_response_tracker(config: Optional[Config] = None) -> ResponseTracker:
|
|
228
232
|
The shared ResponseTracker instance
|
229
233
|
"""
|
230
234
|
global _tracker_instance
|
231
|
-
|
232
|
-
|
233
|
-
|
235
|
+
|
236
|
+
# Fast path - check without lock
|
237
|
+
if _tracker_instance is not None:
|
238
|
+
return _tracker_instance
|
239
|
+
|
240
|
+
# Slow path - acquire lock and double-check
|
241
|
+
with _tracker_lock:
|
242
|
+
if _tracker_instance is None:
|
243
|
+
_tracker_instance = ResponseTracker(config=config)
|
244
|
+
return _tracker_instance
|
234
245
|
|
235
246
|
|
236
247
|
def track_response(
|
@@ -0,0 +1,174 @@
|
|
1
|
+
"""
|
2
|
+
Session Manager Service
|
3
|
+
|
4
|
+
Centralized session ID management with thread-safe singleton pattern.
|
5
|
+
Ensures a single session ID is generated and used across all components.
|
6
|
+
|
7
|
+
This service addresses race conditions and duplicate session ID generation
|
8
|
+
by providing a single source of truth for session identifiers.
|
9
|
+
"""
|
10
|
+
|
11
|
+
import os
|
12
|
+
from datetime import datetime, timezone
|
13
|
+
from threading import Lock
|
14
|
+
from typing import Optional
|
15
|
+
|
16
|
+
from claude_mpm.core.logging_utils import get_logger
|
17
|
+
|
18
|
+
logger = get_logger(__name__)
|
19
|
+
|
20
|
+
|
21
|
+
class SessionManager:
|
22
|
+
"""
|
23
|
+
Thread-safe singleton session manager.
|
24
|
+
|
25
|
+
Provides centralized session ID generation and management to prevent
|
26
|
+
duplicate session IDs across different components.
|
27
|
+
|
28
|
+
Uses double-checked locking pattern for thread-safe singleton initialization.
|
29
|
+
"""
|
30
|
+
|
31
|
+
_instance: Optional["SessionManager"] = None
|
32
|
+
_lock = Lock()
|
33
|
+
_initialized = False
|
34
|
+
|
35
|
+
def __new__(cls) -> "SessionManager":
|
36
|
+
"""
|
37
|
+
Create or return the singleton instance using double-checked locking.
|
38
|
+
|
39
|
+
Returns:
|
40
|
+
The singleton SessionManager instance
|
41
|
+
"""
|
42
|
+
# First check without lock (fast path)
|
43
|
+
if cls._instance is None:
|
44
|
+
# Acquire lock for thread safety
|
45
|
+
with cls._lock:
|
46
|
+
# Double-check inside lock
|
47
|
+
if cls._instance is None:
|
48
|
+
cls._instance = super().__new__(cls)
|
49
|
+
return cls._instance
|
50
|
+
|
51
|
+
def __init__(self):
|
52
|
+
"""
|
53
|
+
Initialize the session manager (only once).
|
54
|
+
|
55
|
+
This method uses an initialization flag to ensure it only
|
56
|
+
runs once, even if __init__ is called multiple times.
|
57
|
+
"""
|
58
|
+
# Use class-level lock to ensure thread-safe initialization
|
59
|
+
with self.__class__._lock:
|
60
|
+
if self.__class__._initialized:
|
61
|
+
return
|
62
|
+
|
63
|
+
# Generate session ID once during initialization
|
64
|
+
self._session_id = self._generate_session_id()
|
65
|
+
self._session_start_time = datetime.now(timezone.utc)
|
66
|
+
|
67
|
+
# Mark as initialized
|
68
|
+
self.__class__._initialized = True
|
69
|
+
|
70
|
+
logger.info(
|
71
|
+
f"SessionManager initialized with session ID: {self._session_id}"
|
72
|
+
)
|
73
|
+
|
74
|
+
def _generate_session_id(self) -> str:
|
75
|
+
"""
|
76
|
+
Generate or retrieve a session ID.
|
77
|
+
|
78
|
+
Checks environment variables first, then generates a timestamp-based ID.
|
79
|
+
|
80
|
+
Returns:
|
81
|
+
A unique session identifier
|
82
|
+
"""
|
83
|
+
# Check environment variables in order of preference
|
84
|
+
env_vars = ["CLAUDE_SESSION_ID", "ANTHROPIC_SESSION_ID", "SESSION_ID"]
|
85
|
+
|
86
|
+
for env_var in env_vars:
|
87
|
+
session_id = os.environ.get(env_var)
|
88
|
+
if session_id:
|
89
|
+
logger.info(f"Using session ID from {env_var}: {session_id}")
|
90
|
+
return session_id
|
91
|
+
|
92
|
+
# Generate timestamp-based session ID
|
93
|
+
session_id = datetime.now(timezone.utc).strftime("%Y%m%d_%H%M%S")
|
94
|
+
logger.info(f"Generated new session ID: {session_id}")
|
95
|
+
return session_id
|
96
|
+
|
97
|
+
def get_session_id(self) -> str:
|
98
|
+
"""
|
99
|
+
Get the current session ID.
|
100
|
+
|
101
|
+
Thread-safe method to retrieve the session ID.
|
102
|
+
|
103
|
+
Returns:
|
104
|
+
The current session ID
|
105
|
+
"""
|
106
|
+
return self._session_id
|
107
|
+
|
108
|
+
def get_session_start_time(self) -> datetime:
|
109
|
+
"""
|
110
|
+
Get the session start time.
|
111
|
+
|
112
|
+
Returns:
|
113
|
+
The datetime when the session was initialized
|
114
|
+
"""
|
115
|
+
return self._session_start_time
|
116
|
+
|
117
|
+
def set_session_id(self, session_id: str) -> None:
|
118
|
+
"""
|
119
|
+
Override the session ID.
|
120
|
+
|
121
|
+
This should only be used in special circumstances, as it can
|
122
|
+
break the single session ID guarantee.
|
123
|
+
|
124
|
+
Args:
|
125
|
+
session_id: The new session ID to use
|
126
|
+
"""
|
127
|
+
with self.__class__._lock:
|
128
|
+
old_id = self._session_id
|
129
|
+
if old_id != session_id:
|
130
|
+
self._session_id = session_id
|
131
|
+
logger.warning(f"Session ID changed from {old_id} to {session_id}")
|
132
|
+
else:
|
133
|
+
logger.debug(f"Session ID already set to {session_id}, no change needed")
|
134
|
+
|
135
|
+
@classmethod
|
136
|
+
def reset(cls) -> None:
|
137
|
+
"""
|
138
|
+
Reset the singleton instance (mainly for testing).
|
139
|
+
|
140
|
+
This method should not be used in production code.
|
141
|
+
"""
|
142
|
+
with cls._lock:
|
143
|
+
cls._instance = None
|
144
|
+
cls._initialized = False
|
145
|
+
logger.debug("SessionManager singleton reset")
|
146
|
+
|
147
|
+
|
148
|
+
# Global accessor function
|
149
|
+
_manager: Optional[SessionManager] = None
|
150
|
+
|
151
|
+
|
152
|
+
def get_session_manager() -> SessionManager:
|
153
|
+
"""
|
154
|
+
Get the global SessionManager instance.
|
155
|
+
|
156
|
+
Thread-safe accessor that ensures a single SessionManager exists.
|
157
|
+
|
158
|
+
Returns:
|
159
|
+
The singleton SessionManager instance
|
160
|
+
"""
|
161
|
+
global _manager
|
162
|
+
if _manager is None:
|
163
|
+
_manager = SessionManager()
|
164
|
+
return _manager
|
165
|
+
|
166
|
+
|
167
|
+
def get_session_id() -> str:
|
168
|
+
"""
|
169
|
+
Convenience function to get the current session ID.
|
170
|
+
|
171
|
+
Returns:
|
172
|
+
The current session ID
|
173
|
+
"""
|
174
|
+
return get_session_manager().get_session_id()
|
@@ -1,5 +1,5 @@
|
|
1
1
|
claude_mpm/BUILD_NUMBER,sha256=toytnNjkIKPgQaGwDqQdC1rpNTAdSEc6Vja50d7Ovug,4
|
2
|
-
claude_mpm/VERSION,sha256=
|
2
|
+
claude_mpm/VERSION,sha256=f5wbxv1InvG9hB7daBjMUVwWCbFMx-PRPiN2wYxs6Ns,6
|
3
3
|
claude_mpm/__init__.py,sha256=lyTZAYGH4DTaFGLRNWJKk5Q5oTjzN5I6AXmfVX-Jff0,1512
|
4
4
|
claude_mpm/__main__.py,sha256=Ro5UBWBoQaSAIoSqWAr7zkbLyvi4sSy28WShqAhKJG0,723
|
5
5
|
claude_mpm/constants.py,sha256=cChN3myrAcF3jC-6DvHnBFTEnwlDk-TAsIXPvUZr_yw,5953
|
@@ -8,14 +8,14 @@ claude_mpm/ticket_wrapper.py,sha256=qe5xY579t7_7fK5nyeAfHN_fr7CXdeOD3jfXEc8-7yo,
|
|
8
8
|
claude_mpm/agents/BASE_AGENT_TEMPLATE.md,sha256=aK9qxS1FRpm_8VaB5GI2I6YA9Wr8dGHuea_txMFe44M,5524
|
9
9
|
claude_mpm/agents/BASE_DOCUMENTATION.md,sha256=iGub94w3IRURz2PwT0YrfNegMlEzgZ9mzeWa_WBk1rA,1504
|
10
10
|
claude_mpm/agents/BASE_ENGINEER.md,sha256=lXkA6KoCopsRTWS1LOx2s5m6S0hT5UT0s3l5owBo0Hc,7491
|
11
|
-
claude_mpm/agents/BASE_OPS.md,sha256=
|
11
|
+
claude_mpm/agents/BASE_OPS.md,sha256=azAjZTrj77IZIBgZxX2hcjPOQMznV0v6B4ZWNUhAT9g,7636
|
12
12
|
claude_mpm/agents/BASE_PM.md,sha256=0n8b45wdRMb9ODLd8tiUu7fBP-UR33Bj0LS-AzHLXNE,3960
|
13
13
|
claude_mpm/agents/BASE_QA.md,sha256=tR4RH63IwxidDXlSnSIRRaoGtmVpJp-0_GkQkmFUbjM,1590
|
14
14
|
claude_mpm/agents/BASE_RESEARCH.md,sha256=2DZhDd5XxWWtsyNTBIwvtNWBu1JpFy5R5SAZDHh0otU,1690
|
15
15
|
claude_mpm/agents/INSTRUCTIONS_OLD_DEPRECATED.md,sha256=zQZhrhVq9NLCtSjVX-aC0xcgueemSuPhKyv0SjEOyIQ,25852
|
16
16
|
claude_mpm/agents/MEMORY.md,sha256=KbRwY_RYdOvTvFC2DD-ATfwjHkQWJ5PIjlGws_7RmjI,3307
|
17
17
|
claude_mpm/agents/OUTPUT_STYLE.md,sha256=IYbo4jmICihrfnChbdrRpwVk4VobCcNyYqZqd53VXMk,533
|
18
|
-
claude_mpm/agents/PM_INSTRUCTIONS.md,sha256=
|
18
|
+
claude_mpm/agents/PM_INSTRUCTIONS.md,sha256=NAT35pAaM0VxgtMtspDh2Nz4K_OmTTNZ0CvODevwwws,30856
|
19
19
|
claude_mpm/agents/WORKFLOW.md,sha256=m4hjQNX8tZKNlyVPjvGJJXc-UG3yzkscmu9Nwfcddsw,2373
|
20
20
|
claude_mpm/agents/__init__.py,sha256=jRFxvV_DIZ-NdENa-703Xu3YpwvlQj6yv-mQ6FgmldM,3220
|
21
21
|
claude_mpm/agents/agent-template.yaml,sha256=mRlz5Yd0SmknTeoJWgFkZXzEF5T7OmGBJGs2-KPT93k,1969
|
@@ -38,7 +38,7 @@ claude_mpm/agents/templates/documentation.json,sha256=Hp9GADw0Wttmxe2pxTCg40DT1A
|
|
38
38
|
claude_mpm/agents/templates/engineer.json,sha256=tAWKqt35OyL0RUQgTSeX9nVtcjF94ND-WbflXStAXHA,8222
|
39
39
|
claude_mpm/agents/templates/gcp_ops_agent.json,sha256=v2exIGCzPLBDu5M4CCxZ1k3EQfrV0jc6T9C2ecPjScY,10812
|
40
40
|
claude_mpm/agents/templates/imagemagick.json,sha256=6Zy4W_q6BYkJxd_KqDT2B3GBkwhn7VKT9ZVj-O_tj0Q,17747
|
41
|
-
claude_mpm/agents/templates/local_ops_agent.json,sha256=
|
41
|
+
claude_mpm/agents/templates/local_ops_agent.json,sha256=h92JVFa3pYMRvkw2yEVxfTuyUQ2PFhgaWw_7uD2CmJ0,9947
|
42
42
|
claude_mpm/agents/templates/memory_manager.json,sha256=b6bTMLFShY4-884pgjc6wsfLICcVx17ZrRj7y-NH61w,12613
|
43
43
|
claude_mpm/agents/templates/nextjs_engineer.json,sha256=Y2NUxJ3D6FFkDdk83kTqbJ70IZKAVJZkePbyEX_hESo,18786
|
44
44
|
claude_mpm/agents/templates/ops.json,sha256=zp1uBfxdp7Atja0oLcNr8TAv-CQuK4mAnbfnLQMFIF4,10904
|
@@ -403,23 +403,24 @@ claude_mpm/scripts/socketio_daemon.py,sha256=I1n0ny6UZTQWKN-_ZiNKK37jJTRgRESyHDA
|
|
403
403
|
claude_mpm/scripts/start_activity_logging.py,sha256=1G9bFYiBSkpxSRXyKht73nL5gH-4zwukLutWWKAipGg,2869
|
404
404
|
claude_mpm/services/__init__.py,sha256=X10comSYoSvoi4jaz9a7ztqcYhCZMX7QmX7nwHGJjCM,7495
|
405
405
|
claude_mpm/services/agent_capabilities_service.py,sha256=8-LA1JuTF9IZRBT0AvU4HF9OBMCyySTOZGNuX17T6JM,10776
|
406
|
-
claude_mpm/services/async_session_logger.py,sha256=
|
407
|
-
claude_mpm/services/claude_session_logger.py,sha256=
|
406
|
+
claude_mpm/services/async_session_logger.py,sha256=zheHivwLakwIbQSJ5geMJtB9RU9IOxZjQJoxHsQuAy4,23880
|
407
|
+
claude_mpm/services/claude_session_logger.py,sha256=zKw5X1rGv7LxTEw7xLQujv1GTV9cCRPiW7paHLOWcYU,11157
|
408
408
|
claude_mpm/services/command_deployment_service.py,sha256=FxrHWuhvEaYL6PmjCN7Y0TlGWWIDHkzm_0UwvqI2C3A,6132
|
409
409
|
claude_mpm/services/command_handler_service.py,sha256=LdKnujKUgrCYrvKvmCXaUMk7JGFJsyNeiKnDFdR8ox8,7031
|
410
410
|
claude_mpm/services/event_aggregator.py,sha256=DDcehIZVpiEDzs9o18gDZyvjMBHCq2H8HF4h0ofG9d4,20250
|
411
411
|
claude_mpm/services/exceptions.py,sha256=5lVZETr_6-xk0ItH7BTfYUiX5RlckS1e8ah_UalYG9c,26475
|
412
412
|
claude_mpm/services/hook_installer_service.py,sha256=z3kKeriEY1Y9bFesuGlHBxhCtc0Wzd3Zv02k2_rEyGo,19727
|
413
413
|
claude_mpm/services/hook_service.py,sha256=rZnMn_4qxX5g9KAn0IQdoG50WmySNfsTmfG0XHuRHXk,15737
|
414
|
-
claude_mpm/services/mcp_config_manager.py,sha256=
|
414
|
+
claude_mpm/services/mcp_config_manager.py,sha256=2uukgzVImMQroNlwKgWhxDLi0UzJ0CP4L_dSK3bFcy4,62643
|
415
415
|
claude_mpm/services/mcp_service_verifier.py,sha256=yxybULGAjde3oMqwQ92BiOthlAJKfS_ierPkShFoDHE,25655
|
416
416
|
claude_mpm/services/memory_hook_service.py,sha256=pRlTClkRcw30Jhwbha4BC8IMdzKZxF8aWqf52JlntgY,11600
|
417
417
|
claude_mpm/services/monitor_build_service.py,sha256=8gWR9CaqgXdG6-OjOFXGpk28GCcJTlHhojkUYnMCebI,12160
|
418
418
|
claude_mpm/services/port_manager.py,sha256=CYqLh8Ss_-aoYEXV3G6uZkGexpsRK_XTBL0bV4P3tSI,22838
|
419
419
|
claude_mpm/services/recovery_manager.py,sha256=ptUYsguF6oKWnJnzPRSBuzUFVDXIcvsS3svT6MBTqCQ,25686
|
420
|
-
claude_mpm/services/response_tracker.py,sha256=
|
420
|
+
claude_mpm/services/response_tracker.py,sha256=KsmQOhRMMOx9_bqmyCY0cjknnT9ncaj4D1i9bNpf8fc,9574
|
421
421
|
claude_mpm/services/runner_configuration_service.py,sha256=Qs84yrZfQv-DC0I2Xah1Qt9eunH4gS7LNMZ0mmymcqA,21311
|
422
422
|
claude_mpm/services/session_management_service.py,sha256=DdFeL_oPO-FGKyTjaDkAnyzZAFckmdT54U5z2QC4bn8,10061
|
423
|
+
claude_mpm/services/session_manager.py,sha256=V0a0vpBNRyDz67Ku27agp-nsOU_5LTD2lvEpGPAnWAw,5106
|
423
424
|
claude_mpm/services/socketio_client_manager.py,sha256=cZjIsnoi2VPXFA-5pNhoz5Vv3qv0iuSTy510TgAJU4U,18179
|
424
425
|
claude_mpm/services/socketio_server.py,sha256=yE14_4pHERXBC5L1WQCpIBHuy0tpklsUY_icyl-nLkg,3033
|
425
426
|
claude_mpm/services/subprocess_launcher_service.py,sha256=b8FeO0kh6AblWqnFX4XtSxEw93tENCczVvK0OjbYvpk,10999
|
@@ -776,9 +777,9 @@ claude_mpm/utils/subprocess_utils.py,sha256=D0izRT8anjiUb_JG72zlJR_JAw1cDkb7kalN
|
|
776
777
|
claude_mpm/validation/__init__.py,sha256=YZhwE3mhit-lslvRLuwfX82xJ_k4haZeKmh4IWaVwtk,156
|
777
778
|
claude_mpm/validation/agent_validator.py,sha256=Nm2WmcbCb0EwOG4nFcikc3wVdiiAfjGBBI3YoR6ainQ,20915
|
778
779
|
claude_mpm/validation/frontmatter_validator.py,sha256=IDBOCBweO6umydSnUJjBh81sKk3cy9hRFYm61DCiXbI,7020
|
779
|
-
claude_mpm-4.5.
|
780
|
-
claude_mpm-4.5.
|
781
|
-
claude_mpm-4.5.
|
782
|
-
claude_mpm-4.5.
|
783
|
-
claude_mpm-4.5.
|
784
|
-
claude_mpm-4.5.
|
780
|
+
claude_mpm-4.5.8.dist-info/licenses/LICENSE,sha256=lpaivOlPuBZW1ds05uQLJJswy8Rp_HMNieJEbFlqvLk,1072
|
781
|
+
claude_mpm-4.5.8.dist-info/METADATA,sha256=INLLT4P_neAeA3jZvG2hn9x246XElymx0iF3yt5-Hgs,17517
|
782
|
+
claude_mpm-4.5.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
783
|
+
claude_mpm-4.5.8.dist-info/entry_points.txt,sha256=Vlw3GNi-OtTpKSrez04iNrPmxNxYDpIWxmJCxiZ5Tx8,526
|
784
|
+
claude_mpm-4.5.8.dist-info/top_level.txt,sha256=1nUg3FEaBySgm8t-s54jK5zoPnu3_eY6EP6IOlekyHA,11
|
785
|
+
claude_mpm-4.5.8.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|