claude-mpm 5.1.9__py3-none-any.whl → 5.4.14__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.

Potentially problematic release.


This version of claude-mpm might be problematic. Click here for more details.

Files changed (162) hide show
  1. claude_mpm/VERSION +1 -1
  2. claude_mpm/__init__.py +4 -0
  3. claude_mpm/agents/PM_INSTRUCTIONS.md +85 -0
  4. claude_mpm/agents/agent_loader.py +13 -44
  5. claude_mpm/agents/templates/circuit-breakers.md +138 -1
  6. claude_mpm/cli/__main__.py +4 -0
  7. claude_mpm/cli/commands/agent_state_manager.py +8 -17
  8. claude_mpm/cli/commands/auto_configure.py +210 -25
  9. claude_mpm/cli/commands/config.py +88 -2
  10. claude_mpm/cli/commands/configure.py +1097 -158
  11. claude_mpm/cli/commands/configure_agent_display.py +15 -6
  12. claude_mpm/cli/commands/mpm_init/core.py +160 -46
  13. claude_mpm/cli/commands/mpm_init/knowledge_extractor.py +481 -0
  14. claude_mpm/cli/commands/mpm_init/prompts.py +280 -0
  15. claude_mpm/cli/commands/skills.py +21 -2
  16. claude_mpm/cli/commands/summarize.py +413 -0
  17. claude_mpm/cli/executor.py +11 -3
  18. claude_mpm/cli/parsers/base_parser.py +5 -0
  19. claude_mpm/cli/parsers/config_parser.py +153 -83
  20. claude_mpm/cli/parsers/skills_parser.py +3 -2
  21. claude_mpm/cli/startup.py +333 -89
  22. claude_mpm/commands/mpm-config.md +266 -0
  23. claude_mpm/commands/{mpm-ticket-organize.md → mpm-organize.md} +4 -5
  24. claude_mpm/config/agent_sources.py +27 -0
  25. claude_mpm/core/framework/formatters/content_formatter.py +3 -13
  26. claude_mpm/core/framework/loaders/agent_loader.py +8 -5
  27. claude_mpm/core/framework_loader.py +4 -2
  28. claude_mpm/core/logger.py +13 -0
  29. claude_mpm/core/socketio_pool.py +3 -3
  30. claude_mpm/core/unified_agent_registry.py +5 -15
  31. claude_mpm/hooks/claude_hooks/correlation_manager.py +60 -0
  32. claude_mpm/hooks/claude_hooks/event_handlers.py +206 -78
  33. claude_mpm/hooks/claude_hooks/hook_handler.py +6 -0
  34. claude_mpm/hooks/claude_hooks/installer.py +33 -10
  35. claude_mpm/hooks/claude_hooks/memory_integration.py +26 -9
  36. claude_mpm/hooks/claude_hooks/response_tracking.py +2 -3
  37. claude_mpm/hooks/claude_hooks/services/connection_manager.py +4 -0
  38. claude_mpm/hooks/memory_integration_hook.py +46 -1
  39. claude_mpm/init.py +0 -19
  40. claude_mpm/scripts/claude-hook-handler.sh +58 -18
  41. claude_mpm/scripts/launch_monitor.py +93 -13
  42. claude_mpm/services/agents/agent_recommendation_service.py +278 -0
  43. claude_mpm/services/agents/agent_review_service.py +280 -0
  44. claude_mpm/services/agents/deployment/agent_discovery_service.py +2 -3
  45. claude_mpm/services/agents/deployment/agent_template_builder.py +4 -2
  46. claude_mpm/services/agents/deployment/multi_source_deployment_service.py +78 -9
  47. claude_mpm/services/agents/deployment/remote_agent_discovery_service.py +335 -53
  48. claude_mpm/services/agents/git_source_manager.py +34 -0
  49. claude_mpm/services/agents/loading/base_agent_manager.py +1 -13
  50. claude_mpm/services/agents/sources/git_source_sync_service.py +8 -1
  51. claude_mpm/services/agents/toolchain_detector.py +10 -6
  52. claude_mpm/services/analysis/__init__.py +11 -1
  53. claude_mpm/services/analysis/clone_detector.py +1030 -0
  54. claude_mpm/services/command_deployment_service.py +71 -10
  55. claude_mpm/services/event_bus/config.py +3 -1
  56. claude_mpm/services/git/git_operations_service.py +93 -8
  57. claude_mpm/services/monitor/daemon.py +9 -2
  58. claude_mpm/services/monitor/daemon_manager.py +39 -3
  59. claude_mpm/services/monitor/server.py +225 -19
  60. claude_mpm/services/self_upgrade_service.py +120 -12
  61. claude_mpm/services/skills/__init__.py +3 -0
  62. claude_mpm/services/skills/git_skill_source_manager.py +32 -2
  63. claude_mpm/services/skills/selective_skill_deployer.py +230 -0
  64. claude_mpm/services/skills/skill_to_agent_mapper.py +406 -0
  65. claude_mpm/services/skills_deployer.py +64 -3
  66. claude_mpm/services/socketio/event_normalizer.py +15 -1
  67. claude_mpm/services/socketio/server/core.py +160 -21
  68. claude_mpm/services/version_control/git_operations.py +103 -0
  69. claude_mpm/utils/agent_filters.py +17 -44
  70. {claude_mpm-5.1.9.dist-info → claude_mpm-5.4.14.dist-info}/METADATA +47 -84
  71. {claude_mpm-5.1.9.dist-info → claude_mpm-5.4.14.dist-info}/RECORD +76 -150
  72. claude_mpm-5.4.14.dist-info/entry_points.txt +5 -0
  73. claude_mpm-5.4.14.dist-info/licenses/LICENSE +94 -0
  74. claude_mpm-5.4.14.dist-info/licenses/LICENSE-FAQ.md +153 -0
  75. claude_mpm/agents/BASE_AGENT_TEMPLATE.md +0 -292
  76. claude_mpm/agents/BASE_DOCUMENTATION.md +0 -53
  77. claude_mpm/agents/BASE_ENGINEER.md +0 -658
  78. claude_mpm/agents/BASE_OPS.md +0 -219
  79. claude_mpm/agents/BASE_PM.md +0 -480
  80. claude_mpm/agents/BASE_PROMPT_ENGINEER.md +0 -787
  81. claude_mpm/agents/BASE_QA.md +0 -167
  82. claude_mpm/agents/BASE_RESEARCH.md +0 -53
  83. claude_mpm/agents/base_agent.json +0 -31
  84. claude_mpm/agents/base_agent_loader.py +0 -601
  85. claude_mpm/cli/ticket_cli.py +0 -35
  86. claude_mpm/commands/mpm-config-view.md +0 -150
  87. claude_mpm/dashboard/analysis_runner.py +0 -455
  88. claude_mpm/dashboard/index.html +0 -13
  89. claude_mpm/dashboard/open_dashboard.py +0 -66
  90. claude_mpm/dashboard/static/css/activity.css +0 -1958
  91. claude_mpm/dashboard/static/css/connection-status.css +0 -370
  92. claude_mpm/dashboard/static/css/dashboard.css +0 -4701
  93. claude_mpm/dashboard/static/js/components/activity-tree.js +0 -1871
  94. claude_mpm/dashboard/static/js/components/agent-hierarchy.js +0 -777
  95. claude_mpm/dashboard/static/js/components/agent-inference.js +0 -956
  96. claude_mpm/dashboard/static/js/components/build-tracker.js +0 -333
  97. claude_mpm/dashboard/static/js/components/code-simple.js +0 -857
  98. claude_mpm/dashboard/static/js/components/connection-debug.js +0 -654
  99. claude_mpm/dashboard/static/js/components/diff-viewer.js +0 -891
  100. claude_mpm/dashboard/static/js/components/event-processor.js +0 -542
  101. claude_mpm/dashboard/static/js/components/event-viewer.js +0 -1155
  102. claude_mpm/dashboard/static/js/components/export-manager.js +0 -368
  103. claude_mpm/dashboard/static/js/components/file-change-tracker.js +0 -443
  104. claude_mpm/dashboard/static/js/components/file-change-viewer.js +0 -690
  105. claude_mpm/dashboard/static/js/components/file-tool-tracker.js +0 -724
  106. claude_mpm/dashboard/static/js/components/file-viewer.js +0 -580
  107. claude_mpm/dashboard/static/js/components/hud-library-loader.js +0 -211
  108. claude_mpm/dashboard/static/js/components/hud-manager.js +0 -671
  109. claude_mpm/dashboard/static/js/components/hud-visualizer.js +0 -1718
  110. claude_mpm/dashboard/static/js/components/module-viewer.js +0 -2764
  111. claude_mpm/dashboard/static/js/components/session-manager.js +0 -579
  112. claude_mpm/dashboard/static/js/components/socket-manager.js +0 -368
  113. claude_mpm/dashboard/static/js/components/ui-state-manager.js +0 -749
  114. claude_mpm/dashboard/static/js/components/unified-data-viewer.js +0 -1824
  115. claude_mpm/dashboard/static/js/components/working-directory.js +0 -920
  116. claude_mpm/dashboard/static/js/connection-manager.js +0 -536
  117. claude_mpm/dashboard/static/js/dashboard.js +0 -1914
  118. claude_mpm/dashboard/static/js/extension-error-handler.js +0 -164
  119. claude_mpm/dashboard/static/js/socket-client.js +0 -1474
  120. claude_mpm/dashboard/static/js/tab-isolation-fix.js +0 -185
  121. claude_mpm/dashboard/static/socket.io.min.js +0 -7
  122. claude_mpm/dashboard/static/socket.io.v4.8.1.backup.js +0 -7
  123. claude_mpm/dashboard/templates/code_simple.html +0 -153
  124. claude_mpm/dashboard/templates/index.html +0 -606
  125. claude_mpm/dashboard/test_dashboard.html +0 -372
  126. claude_mpm/scripts/mcp_server.py +0 -75
  127. claude_mpm/scripts/mcp_wrapper.py +0 -39
  128. claude_mpm/services/mcp_gateway/__init__.py +0 -159
  129. claude_mpm/services/mcp_gateway/auto_configure.py +0 -369
  130. claude_mpm/services/mcp_gateway/config/__init__.py +0 -17
  131. claude_mpm/services/mcp_gateway/config/config_loader.py +0 -296
  132. claude_mpm/services/mcp_gateway/config/config_schema.py +0 -243
  133. claude_mpm/services/mcp_gateway/config/configuration.py +0 -429
  134. claude_mpm/services/mcp_gateway/core/__init__.py +0 -43
  135. claude_mpm/services/mcp_gateway/core/base.py +0 -312
  136. claude_mpm/services/mcp_gateway/core/exceptions.py +0 -253
  137. claude_mpm/services/mcp_gateway/core/interfaces.py +0 -443
  138. claude_mpm/services/mcp_gateway/core/process_pool.py +0 -977
  139. claude_mpm/services/mcp_gateway/core/singleton_manager.py +0 -315
  140. claude_mpm/services/mcp_gateway/core/startup_verification.py +0 -316
  141. claude_mpm/services/mcp_gateway/main.py +0 -589
  142. claude_mpm/services/mcp_gateway/registry/__init__.py +0 -12
  143. claude_mpm/services/mcp_gateway/registry/service_registry.py +0 -412
  144. claude_mpm/services/mcp_gateway/registry/tool_registry.py +0 -489
  145. claude_mpm/services/mcp_gateway/server/__init__.py +0 -15
  146. claude_mpm/services/mcp_gateway/server/mcp_gateway.py +0 -414
  147. claude_mpm/services/mcp_gateway/server/stdio_handler.py +0 -372
  148. claude_mpm/services/mcp_gateway/server/stdio_server.py +0 -712
  149. claude_mpm/services/mcp_gateway/tools/__init__.py +0 -36
  150. claude_mpm/services/mcp_gateway/tools/base_adapter.py +0 -485
  151. claude_mpm/services/mcp_gateway/tools/document_summarizer.py +0 -789
  152. claude_mpm/services/mcp_gateway/tools/external_mcp_services.py +0 -654
  153. claude_mpm/services/mcp_gateway/tools/health_check_tool.py +0 -456
  154. claude_mpm/services/mcp_gateway/tools/hello_world.py +0 -551
  155. claude_mpm/services/mcp_gateway/tools/kuzu_memory_service.py +0 -555
  156. claude_mpm/services/mcp_gateway/utils/__init__.py +0 -14
  157. claude_mpm/services/mcp_gateway/utils/package_version_checker.py +0 -160
  158. claude_mpm/services/mcp_gateway/utils/update_preferences.py +0 -170
  159. claude_mpm-5.1.9.dist-info/entry_points.txt +0 -10
  160. claude_mpm-5.1.9.dist-info/licenses/LICENSE +0 -21
  161. {claude_mpm-5.1.9.dist-info → claude_mpm-5.4.14.dist-info}/WHEEL +0 -0
  162. {claude_mpm-5.1.9.dist-info → claude_mpm-5.4.14.dist-info}/top_level.txt +0 -0
@@ -1,579 +0,0 @@
1
- /**
2
- * Session Manager Component
3
- * Handles session selection and management
4
- *
5
- * WHY: Provides session filtering and management for the dashboard, allowing users
6
- * to view events from specific sessions or all sessions.
7
- *
8
- * BROWSER COMPATIBILITY: This component runs in the browser. All Node.js-specific
9
- * globals (process, require, etc.) have been removed. Uses browser-compatible
10
- * alternatives for path handling and defaults.
11
- *
12
- * FIX APPLIED: Removed process.cwd() reference that caused "process is not defined"
13
- * error in browser. Now uses window.location.pathname or hardcoded fallbacks.
14
- */
15
-
16
- class SessionManager {
17
- constructor(socketClient) {
18
- this.socketClient = socketClient;
19
- this.sessions = new Map();
20
- this.currentSessionId = null;
21
- this.selectedSessionId = '';
22
-
23
- this.init();
24
- }
25
-
26
- /**
27
- * Initialize the session manager
28
- */
29
- init() {
30
- this.setupEventHandlers();
31
- this.setupSocketListeners();
32
- this.updateSessionSelect();
33
- }
34
-
35
- /**
36
- * Setup event handlers for UI controls
37
- */
38
- setupEventHandlers() {
39
- // Session selection dropdown
40
- const sessionSelect = document.getElementById('session-select');
41
- if (sessionSelect) {
42
- sessionSelect.addEventListener('change', (e) => {
43
- this.selectedSessionId = e.target.value;
44
- this.onSessionFilterChanged();
45
-
46
- // Load working directory for this session
47
- if (window.dashboard && window.dashboard.loadWorkingDirectoryForSession) {
48
- window.dashboard.loadWorkingDirectoryForSession(e.target.value);
49
- }
50
- });
51
- }
52
-
53
- // Refresh sessions button
54
- const refreshBtn = document.querySelector('button[onclick="refreshSessions()"]');
55
- if (refreshBtn) {
56
- refreshBtn.addEventListener('click', () => {
57
- this.refreshSessions();
58
- });
59
- }
60
- }
61
-
62
- /**
63
- * Setup socket event listeners
64
- */
65
- setupSocketListeners() {
66
- // Listen for socket event updates
67
- this.socketClient.onEventUpdate((events, sessions) => {
68
- // Log the sessions data to debug
69
- console.log('[SESSION-MANAGER] Received sessions update:', sessions);
70
- this.sessions = sessions;
71
- this.updateSessionSelect();
72
- // Update footer info when new events arrive
73
- this.updateFooterInfo();
74
- });
75
-
76
- // Listen for connection status changes
77
- document.addEventListener('socketConnectionStatus', (e) => {
78
- if (e.detail.type === 'connected') {
79
- // Request fresh session data when connected
80
- setTimeout(() => this.refreshSessions(), 1000);
81
- }
82
- });
83
- }
84
-
85
- /**
86
- * Update the session selection dropdown
87
- */
88
- updateSessionSelect() {
89
- const sessionSelect = document.getElementById('session-select');
90
- if (!sessionSelect) return;
91
-
92
- // Store current selection
93
- const currentSelection = sessionSelect.value;
94
-
95
- // Get the default working directory from various sources
96
- let defaultWorkingDir = '/';
97
-
98
- // Try to get from working directory manager
99
- if (window.dashboard && window.dashboard.workingDirectoryManager) {
100
- defaultWorkingDir = window.dashboard.workingDirectoryManager.getDefaultWorkingDir();
101
- } else {
102
- // Fallback: Try to get from header display element
103
- const headerWorkingDir = document.getElementById('working-dir-path');
104
- if (headerWorkingDir?.textContent?.trim()) {
105
- const headerPath = headerWorkingDir.textContent.trim();
106
- if (headerPath !== 'Loading...' && headerPath !== 'Unknown') {
107
- defaultWorkingDir = headerPath;
108
- }
109
- }
110
- }
111
-
112
- console.log('[SESSION-MANAGER] Using default working directory:', defaultWorkingDir);
113
-
114
- // Update "All Sessions" option to show working directory
115
- sessionSelect.innerHTML = `
116
- <option value="">${defaultWorkingDir} | All Sessions</option>
117
- `;
118
-
119
- // Add sessions from the sessions map
120
- if (this.sessions && this.sessions.size > 0) {
121
- const sortedSessions = Array.from(this.sessions.values())
122
- .sort((a, b) => new Date(b.lastActivity || b.startTime) - new Date(a.lastActivity || a.startTime));
123
-
124
- sortedSessions.forEach(session => {
125
- const option = document.createElement('option');
126
- option.value = session.id;
127
-
128
- // Format session display text
129
- const startTime = new Date(session.startTime || session.last_activity).toLocaleString();
130
- const eventCount = session.eventCount || session.event_count || 0;
131
- const isActive = session.id === this.currentSessionId;
132
-
133
- // Extract working directory from session or events
134
- let workingDir = session.working_directory || session.workingDirectory || '';
135
-
136
- // Log for debugging
137
- console.log(`[SESSION-DROPDOWN] Session ${session.id.substring(0, 8)} working_directory:`, workingDir);
138
-
139
- if (!workingDir) {
140
- const sessionData = this.extractSessionInfoFromEvents(session.id);
141
- workingDir = sessionData.workingDir || defaultWorkingDir;
142
- console.log(`[SESSION-DROPDOWN] Extracted working directory from events:`, workingDir);
143
- }
144
-
145
- // Format display: working_directory | session_id...
146
- const shortId = session.id.substring(0, 8);
147
- const dirDisplay = workingDir || defaultWorkingDir;
148
- option.textContent = `${dirDisplay} | ${shortId}...${isActive ? ' [ACTIVE]' : ''}`;
149
- sessionSelect.appendChild(option);
150
- });
151
- }
152
-
153
- // Restore selection if it still exists
154
- if (currentSelection && Array.from(sessionSelect.options).some(opt => opt.value === currentSelection)) {
155
- sessionSelect.value = currentSelection;
156
- this.selectedSessionId = currentSelection;
157
- // Trigger events for restored selection
158
- this.onSessionFilterChanged();
159
- } else {
160
- this.selectedSessionId = sessionSelect.value;
161
- // Trigger events for new selection
162
- if (this.selectedSessionId) {
163
- this.onSessionFilterChanged();
164
- }
165
- }
166
- }
167
-
168
- /**
169
- * Handle session filter change
170
- */
171
- onSessionFilterChanged() {
172
- // Notify event viewer about filter change
173
- const eventViewer = window.eventViewer;
174
- if (eventViewer) {
175
- eventViewer.setSessionFilter(this.selectedSessionId);
176
- }
177
-
178
- // Update footer information
179
- this.updateFooterInfo();
180
-
181
- // Dispatch custom event for other components
182
- document.dispatchEvent(new CustomEvent('sessionFilterChanged', {
183
- detail: { sessionId: this.selectedSessionId }
184
- }));
185
-
186
- // Also dispatch sessionChanged for backward compatibility with other components
187
- document.dispatchEvent(new CustomEvent('sessionChanged', {
188
- detail: { sessionId: this.selectedSessionId }
189
- }));
190
- }
191
-
192
- /**
193
- * Refresh sessions from server
194
- */
195
- refreshSessions() {
196
- if (this.socketClient && this.socketClient.getConnectionState().isConnected) {
197
- console.log('Refreshing sessions...');
198
- this.socketClient.requestStatus();
199
- } else {
200
- console.warn('Cannot refresh sessions: not connected to server');
201
- }
202
- }
203
-
204
- /**
205
- * Update footer information based on selected session
206
- */
207
- updateFooterInfo() {
208
- console.log('[SESSION-DEBUG] updateFooterInfo called, selectedSessionId:', this.selectedSessionId);
209
-
210
- const footerSessionEl = document.getElementById('footer-session');
211
- const footerWorkingDirEl = document.getElementById('footer-working-dir');
212
- const footerGitBranchEl = document.getElementById('footer-git-branch');
213
-
214
- if (!footerSessionEl) {
215
- console.warn('[SESSION-DEBUG] footer-session element not found');
216
- return;
217
- }
218
-
219
- let sessionInfo = 'All Sessions';
220
- // Use browser-compatible fallback for working directory
221
- // WHY: Removed process.cwd() Node.js reference - not available in browser
222
- // BROWSER FIX: Use dashboard manager or server-provided config
223
- let workingDir = window.dashboard?.workingDirectoryManager?.getDefaultWorkingDir() ||
224
- window.dashboardConfig?.workingDirectory ||
225
- '.';
226
- let gitBranch = 'Unknown';
227
-
228
- console.log('[SESSION-DEBUG] Initial values - sessionInfo:', sessionInfo, 'workingDir:', workingDir, 'gitBranch:', gitBranch);
229
-
230
- if (this.selectedSessionId === 'current') {
231
- sessionInfo = this.currentSessionId ?
232
- `Current: ${this.currentSessionId.substring(0, 8)}...` :
233
- 'Current: None';
234
-
235
- // For current session, try to extract info from recent events
236
- if (this.currentSessionId) {
237
- const sessionData = this.extractSessionInfoFromEvents(this.currentSessionId);
238
- // Browser-compatible working directory fallback
239
- workingDir = sessionData.workingDir ||
240
- window.dashboard?.workingDirectoryManager?.getDefaultWorkingDir() ||
241
- window.dashboardConfig?.workingDirectory ||
242
- '.';
243
- gitBranch = sessionData.gitBranch || 'Unknown';
244
- }
245
- } else if (this.selectedSessionId) {
246
- const session = this.sessions.get(this.selectedSessionId);
247
- if (session) {
248
- sessionInfo = `${this.selectedSessionId.substring(0, 8)}...`;
249
- workingDir = session.working_directory || session.workingDirectory || '';
250
- gitBranch = session.git_branch || session.gitBranch || '';
251
-
252
- // If session doesn't have these values, extract from events
253
- if (!workingDir || !gitBranch) {
254
- const sessionData = this.extractSessionInfoFromEvents(this.selectedSessionId);
255
- // Browser-compatible fallback - no process.cwd()
256
- workingDir = workingDir || sessionData.workingDir || window.dashboardConfig?.workingDirectory || '.';
257
- gitBranch = gitBranch || sessionData.gitBranch || '';
258
- }
259
- }
260
- }
261
-
262
- console.log('[SESSION-DEBUG] Final values before setting footer - sessionInfo:', sessionInfo, 'workingDir:', workingDir, 'gitBranch:', gitBranch);
263
-
264
- footerSessionEl.textContent = sessionInfo;
265
- if (footerWorkingDirEl) {
266
- console.log('[SESSION-DEBUG] Setting footer working dir to:', workingDir);
267
- footerWorkingDirEl.textContent = workingDir;
268
- } else {
269
- console.warn('[SESSION-DEBUG] footer-working-dir element not found');
270
- }
271
- if (footerGitBranchEl) {
272
- console.log('[SESSION-DEBUG] Setting footer git branch to:', gitBranch);
273
- footerGitBranchEl.textContent = gitBranch;
274
- } else {
275
- console.warn('[SESSION-DEBUG] footer-git-branch element not found');
276
- }
277
- }
278
-
279
- /**
280
- * Extract working directory and git branch from events for a specific session
281
- * @param {string} sessionId - Session ID to extract info for
282
- * @returns {Object} Object with workingDir and gitBranch properties
283
- */
284
- extractSessionInfoFromEvents(sessionId) {
285
- let workingDir = '';
286
- let gitBranch = '';
287
-
288
- console.log(`[DEBUG] extractSessionInfoFromEvents called for sessionId: ${sessionId}`);
289
-
290
- // Get events from the socket client
291
- const socketClient = this.socketClient;
292
- if (socketClient && socketClient.events) {
293
- console.log(`[DEBUG] Total events available: ${socketClient.events.length}`);
294
-
295
- // Look for session start events or recent events with this session ID
296
- const sessionEvents = socketClient.events.filter(event =>
297
- event.data && event.data.session_id === sessionId
298
- );
299
-
300
- console.log(`[DEBUG] Events matching sessionId ${sessionId}: ${sessionEvents.length}`);
301
-
302
- // Log a few sample events to see their structure
303
- if (sessionEvents.length > 0) {
304
- console.log(`[DEBUG] Sample events for session ${sessionId}:`);
305
-
306
- // Show first 3 events
307
- sessionEvents.slice(0, 3).forEach((event, index) => {
308
- console.log(`[DEBUG] Event ${index + 1}:`, {
309
- type: event.type,
310
- timestamp: event.timestamp,
311
- data_keys: event.data ? Object.keys(event.data) : 'no data',
312
- full_event: event
313
- });
314
- });
315
-
316
- // Show last 3 events if different from first 3
317
- if (sessionEvents.length > 3) {
318
- console.log(`[DEBUG] Last 3 events for session ${sessionId}:`);
319
- sessionEvents.slice(-3).forEach((event, index) => {
320
- console.log(`[DEBUG] Last Event ${index + 1}:`, {
321
- type: event.type,
322
- timestamp: event.timestamp,
323
- data_keys: event.data ? Object.keys(event.data) : 'no data',
324
- full_event: event
325
- });
326
- });
327
- }
328
- }
329
-
330
- // Find the most recent event with working directory and git branch info
331
- for (let i = sessionEvents.length - 1; i >= 0; i--) {
332
- const event = sessionEvents[i];
333
- if (event.data) {
334
- console.log(`[DEBUG] Examining event ${i} data:`, event.data);
335
-
336
- // Check for working directory info
337
- if (!workingDir) {
338
- if (event.data.working_directory) {
339
- workingDir = event.data.working_directory;
340
- console.log(`[DEBUG] Found working_directory: ${workingDir}`);
341
- } else if (event.data.cwd) {
342
- workingDir = event.data.cwd;
343
- console.log(`[DEBUG] Found cwd: ${workingDir}`);
344
- } else if (event.data.instance_info && event.data.instance_info.working_dir) {
345
- workingDir = event.data.instance_info.working_dir;
346
- console.log(`[DEBUG] Found instance_info.working_dir: ${workingDir}`);
347
- }
348
- }
349
-
350
- // Check for git branch info - check all possible field names
351
- if (!gitBranch) {
352
- const possibleBranchFields = [
353
- 'git_branch',
354
- 'gitBranch',
355
- 'branch',
356
- 'git.branch',
357
- 'vcs_branch',
358
- 'current_branch'
359
- ];
360
-
361
- for (const field of possibleBranchFields) {
362
- if (event.data[field]) {
363
- gitBranch = event.data[field];
364
- console.log(`[DEBUG] Found git branch in field '${field}': ${gitBranch}`);
365
- break;
366
- }
367
- }
368
-
369
- // Check nested locations
370
- if (!gitBranch) {
371
- if (event.data.instance_info) {
372
- console.log(`[DEBUG] Checking instance_info for branch:`, event.data.instance_info);
373
- for (const field of possibleBranchFields) {
374
- if (event.data.instance_info[field]) {
375
- gitBranch = event.data.instance_info[field];
376
- console.log(`[DEBUG] Found git branch in instance_info.${field}: ${gitBranch}`);
377
- break;
378
- }
379
- }
380
- }
381
-
382
- if (!gitBranch && event.data.git) {
383
- console.log(`[DEBUG] Checking git object:`, event.data.git);
384
- if (event.data.git.branch) {
385
- gitBranch = event.data.git.branch;
386
- console.log(`[DEBUG] Found git branch in git.branch: ${gitBranch}`);
387
- }
388
- }
389
- }
390
- }
391
-
392
- // If we have both, we can stop looking
393
- if (workingDir && gitBranch) {
394
- console.log(`[DEBUG] Found both workingDir and gitBranch, stopping search`);
395
- break;
396
- }
397
- }
398
- }
399
- } else {
400
- console.log(`[DEBUG] No socket client or events available`);
401
- }
402
-
403
- console.log(`[DEBUG] Final results - workingDir: '${workingDir}', gitBranch: '${gitBranch}'`);
404
- return { workingDir, gitBranch };
405
- }
406
-
407
- /**
408
- * Set current session ID (from server status)
409
- * @param {string} sessionId - Current session ID
410
- */
411
- setCurrentSessionId(sessionId) {
412
- this.currentSessionId = sessionId;
413
- this.updateSessionSelect();
414
- this.updateFooterInfo();
415
- }
416
-
417
- /**
418
- * Add or update a session
419
- * @param {Object} sessionData - Session data
420
- */
421
- addSession(sessionData) {
422
- if (!sessionData.id) return;
423
-
424
- const existingSession = this.sessions.get(sessionData.id);
425
- if (existingSession) {
426
- // Update existing session
427
- Object.assign(existingSession, sessionData);
428
- } else {
429
- // Add new session
430
- this.sessions.set(sessionData.id, {
431
- id: sessionData.id,
432
- startTime: sessionData.startTime || sessionData.start_time || new Date().toISOString(),
433
- lastActivity: sessionData.lastActivity || sessionData.last_activity || new Date().toISOString(),
434
- eventCount: sessionData.eventCount || sessionData.event_count || 0,
435
- working_directory: sessionData.working_directory || sessionData.workingDirectory || '',
436
- git_branch: sessionData.git_branch || sessionData.gitBranch || '',
437
- agent_type: sessionData.agent_type || sessionData.agentType || '',
438
- ...sessionData
439
- });
440
- }
441
-
442
- this.updateSessionSelect();
443
- }
444
-
445
- /**
446
- * Remove a session
447
- * @param {string} sessionId - Session ID to remove
448
- */
449
- removeSession(sessionId) {
450
- if (this.sessions.has(sessionId)) {
451
- this.sessions.delete(sessionId);
452
-
453
- // If the removed session was selected, reset to all sessions
454
- if (this.selectedSessionId === sessionId) {
455
- this.selectedSessionId = '';
456
- const sessionSelect = document.getElementById('session-select');
457
- if (sessionSelect) {
458
- sessionSelect.value = '';
459
- }
460
- this.onSessionFilterChanged();
461
- }
462
-
463
- this.updateSessionSelect();
464
- }
465
- }
466
-
467
- /**
468
- * Get current session filter
469
- * @returns {string} Current session filter
470
- */
471
- getCurrentFilter() {
472
- return this.selectedSessionId;
473
- }
474
-
475
- /**
476
- * Get session information
477
- * @param {string} sessionId - Session ID
478
- * @returns {Object|null} Session data or null if not found
479
- */
480
- getSession(sessionId) {
481
- return this.sessions.get(sessionId) || null;
482
- }
483
-
484
- /**
485
- * Get all sessions
486
- * @returns {Map} All sessions
487
- */
488
- getAllSessions() {
489
- return this.sessions;
490
- }
491
-
492
- /**
493
- * Get current active session ID
494
- * @returns {string|null} Current session ID
495
- */
496
- getCurrentSessionId() {
497
- return this.currentSessionId;
498
- }
499
-
500
- /**
501
- * Clear all sessions
502
- */
503
- clearSessions() {
504
- this.sessions.clear();
505
- this.currentSessionId = null;
506
- this.selectedSessionId = '';
507
- this.updateSessionSelect();
508
- this.updateFooterInfo();
509
- }
510
-
511
- /**
512
- * Export session data
513
- * @returns {Object} Session export data
514
- */
515
- exportSessionData() {
516
- return {
517
- sessions: Array.from(this.sessions.entries()),
518
- currentSessionId: this.currentSessionId,
519
- selectedSessionId: this.selectedSessionId
520
- };
521
- }
522
-
523
- /**
524
- * Import session data
525
- * @param {Object} data - Session import data
526
- */
527
- importSessionData(data) {
528
- if (data.sessions && Array.isArray(data.sessions)) {
529
- this.sessions.clear();
530
- data.sessions.forEach(([id, sessionData]) => {
531
- this.sessions.set(id, sessionData);
532
- });
533
- }
534
-
535
- if (data.currentSessionId) {
536
- this.currentSessionId = data.currentSessionId;
537
- }
538
-
539
- if (data.selectedSessionId !== undefined) {
540
- this.selectedSessionId = data.selectedSessionId;
541
- }
542
-
543
- this.updateSessionSelect();
544
- this.updateFooterInfo();
545
- }
546
-
547
- /**
548
- * Get events for a specific session
549
- * @param {string} sessionId - Session ID to get events for
550
- * @returns {Array} - Filtered events for the session
551
- */
552
- getEventsForSession(sessionId) {
553
- if (!sessionId || !this.socketClient) {
554
- return [];
555
- }
556
-
557
- const allEvents = this.socketClient.events || [];
558
- return allEvents.filter(event => {
559
- // Check for session ID in various possible locations
560
- const eventSessionId = event.session_id ||
561
- (event.data && event.data.session_id) ||
562
- null;
563
- return eventSessionId === sessionId;
564
- });
565
- }
566
- }
567
-
568
- // Global functions for backward compatibility
569
- window.refreshSessions = function() {
570
- if (window.sessionManager) {
571
- window.sessionManager.refreshSessions();
572
- }
573
- };
574
-
575
- // Export for global use
576
- window.SessionManager = SessionManager;
577
- // ES6 Module export
578
- export { SessionManager };
579
- export default SessionManager;