claude-mpm 4.1.8__py3-none-any.whl → 4.1.11__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.
Files changed (111) hide show
  1. claude_mpm/VERSION +1 -1
  2. claude_mpm/agents/INSTRUCTIONS.md +26 -1
  3. claude_mpm/agents/agents_metadata.py +57 -0
  4. claude_mpm/agents/templates/.claude-mpm/memories/README.md +17 -0
  5. claude_mpm/agents/templates/.claude-mpm/memories/engineer_memories.md +3 -0
  6. claude_mpm/agents/templates/agent-manager.json +263 -17
  7. claude_mpm/agents/templates/agentic_coder_optimizer.json +222 -0
  8. claude_mpm/agents/templates/code_analyzer.json +18 -8
  9. claude_mpm/agents/templates/engineer.json +1 -1
  10. claude_mpm/agents/templates/logs/prompts/agent_engineer_20250826_014258_728.md +39 -0
  11. claude_mpm/agents/templates/qa.json +1 -1
  12. claude_mpm/agents/templates/research.json +1 -1
  13. claude_mpm/cli/__init__.py +15 -0
  14. claude_mpm/cli/commands/__init__.py +6 -0
  15. claude_mpm/cli/commands/analyze.py +548 -0
  16. claude_mpm/cli/commands/analyze_code.py +524 -0
  17. claude_mpm/cli/commands/configure.py +78 -28
  18. claude_mpm/cli/commands/configure_tui.py +62 -60
  19. claude_mpm/cli/commands/dashboard.py +288 -0
  20. claude_mpm/cli/commands/debug.py +1386 -0
  21. claude_mpm/cli/commands/mpm_init.py +427 -0
  22. claude_mpm/cli/commands/mpm_init_handler.py +83 -0
  23. claude_mpm/cli/parsers/analyze_code_parser.py +170 -0
  24. claude_mpm/cli/parsers/analyze_parser.py +135 -0
  25. claude_mpm/cli/parsers/base_parser.py +44 -0
  26. claude_mpm/cli/parsers/dashboard_parser.py +113 -0
  27. claude_mpm/cli/parsers/debug_parser.py +319 -0
  28. claude_mpm/cli/parsers/mpm_init_parser.py +122 -0
  29. claude_mpm/constants.py +13 -1
  30. claude_mpm/core/framework_loader.py +148 -6
  31. claude_mpm/core/log_manager.py +16 -13
  32. claude_mpm/core/logger.py +1 -1
  33. claude_mpm/core/unified_agent_registry.py +1 -1
  34. claude_mpm/dashboard/.claude-mpm/socketio-instances.json +1 -0
  35. claude_mpm/dashboard/analysis_runner.py +455 -0
  36. claude_mpm/dashboard/static/built/components/activity-tree.js +2 -0
  37. claude_mpm/dashboard/static/built/components/agent-inference.js +1 -1
  38. claude_mpm/dashboard/static/built/components/code-tree.js +2 -0
  39. claude_mpm/dashboard/static/built/components/code-viewer.js +2 -0
  40. claude_mpm/dashboard/static/built/components/event-viewer.js +1 -1
  41. claude_mpm/dashboard/static/built/components/file-tool-tracker.js +1 -1
  42. claude_mpm/dashboard/static/built/components/module-viewer.js +1 -1
  43. claude_mpm/dashboard/static/built/components/session-manager.js +1 -1
  44. claude_mpm/dashboard/static/built/components/working-directory.js +1 -1
  45. claude_mpm/dashboard/static/built/dashboard.js +1 -1
  46. claude_mpm/dashboard/static/built/socket-client.js +1 -1
  47. claude_mpm/dashboard/static/css/activity.css +549 -0
  48. claude_mpm/dashboard/static/css/code-tree.css +1175 -0
  49. claude_mpm/dashboard/static/css/dashboard.css +245 -0
  50. claude_mpm/dashboard/static/dist/components/activity-tree.js +2 -0
  51. claude_mpm/dashboard/static/dist/components/code-tree.js +2 -0
  52. claude_mpm/dashboard/static/dist/components/code-viewer.js +2 -0
  53. claude_mpm/dashboard/static/dist/components/event-viewer.js +1 -1
  54. claude_mpm/dashboard/static/dist/components/session-manager.js +1 -1
  55. claude_mpm/dashboard/static/dist/components/working-directory.js +1 -1
  56. claude_mpm/dashboard/static/dist/dashboard.js +1 -1
  57. claude_mpm/dashboard/static/dist/socket-client.js +1 -1
  58. claude_mpm/dashboard/static/js/components/activity-tree.js +1338 -0
  59. claude_mpm/dashboard/static/js/components/code-tree.js +2535 -0
  60. claude_mpm/dashboard/static/js/components/code-viewer.js +480 -0
  61. claude_mpm/dashboard/static/js/components/event-viewer.js +59 -9
  62. claude_mpm/dashboard/static/js/components/session-manager.js +40 -4
  63. claude_mpm/dashboard/static/js/components/socket-manager.js +12 -0
  64. claude_mpm/dashboard/static/js/components/ui-state-manager.js +4 -0
  65. claude_mpm/dashboard/static/js/components/working-directory.js +17 -1
  66. claude_mpm/dashboard/static/js/dashboard.js +51 -0
  67. claude_mpm/dashboard/static/js/socket-client.js +465 -29
  68. claude_mpm/dashboard/templates/index.html +182 -4
  69. claude_mpm/hooks/claude_hooks/hook_handler.py +182 -5
  70. claude_mpm/hooks/claude_hooks/installer.py +386 -113
  71. claude_mpm/scripts/claude-hook-handler.sh +161 -0
  72. claude_mpm/scripts/socketio_daemon.py +121 -8
  73. claude_mpm/services/agents/deployment/agent_lifecycle_manager_refactored.py +2 -2
  74. claude_mpm/services/agents/deployment/agent_record_service.py +1 -2
  75. claude_mpm/services/agents/memory/memory_format_service.py +1 -3
  76. claude_mpm/services/cli/agent_cleanup_service.py +1 -5
  77. claude_mpm/services/cli/agent_dependency_service.py +1 -1
  78. claude_mpm/services/cli/agent_validation_service.py +3 -4
  79. claude_mpm/services/cli/dashboard_launcher.py +2 -3
  80. claude_mpm/services/cli/startup_checker.py +0 -11
  81. claude_mpm/services/core/cache_manager.py +1 -3
  82. claude_mpm/services/core/path_resolver.py +1 -4
  83. claude_mpm/services/core/service_container.py +2 -2
  84. claude_mpm/services/diagnostics/checks/instructions_check.py +1 -2
  85. claude_mpm/services/infrastructure/monitoring/__init__.py +11 -11
  86. claude_mpm/services/infrastructure/monitoring.py +11 -11
  87. claude_mpm/services/project/architecture_analyzer.py +1 -1
  88. claude_mpm/services/project/dependency_analyzer.py +4 -4
  89. claude_mpm/services/project/language_analyzer.py +3 -3
  90. claude_mpm/services/project/metrics_collector.py +3 -6
  91. claude_mpm/services/socketio/event_normalizer.py +64 -0
  92. claude_mpm/services/socketio/handlers/__init__.py +2 -0
  93. claude_mpm/services/socketio/handlers/code_analysis.py +672 -0
  94. claude_mpm/services/socketio/handlers/registry.py +2 -0
  95. claude_mpm/services/socketio/server/connection_manager.py +6 -4
  96. claude_mpm/services/socketio/server/core.py +100 -11
  97. claude_mpm/services/socketio/server/main.py +8 -2
  98. claude_mpm/services/visualization/__init__.py +19 -0
  99. claude_mpm/services/visualization/mermaid_generator.py +938 -0
  100. claude_mpm/tools/__main__.py +208 -0
  101. claude_mpm/tools/code_tree_analyzer.py +1596 -0
  102. claude_mpm/tools/code_tree_builder.py +631 -0
  103. claude_mpm/tools/code_tree_events.py +416 -0
  104. claude_mpm/tools/socketio_debug.py +671 -0
  105. {claude_mpm-4.1.8.dist-info → claude_mpm-4.1.11.dist-info}/METADATA +2 -1
  106. {claude_mpm-4.1.8.dist-info → claude_mpm-4.1.11.dist-info}/RECORD +110 -74
  107. claude_mpm/agents/schema/agent_schema.json +0 -314
  108. {claude_mpm-4.1.8.dist-info → claude_mpm-4.1.11.dist-info}/WHEEL +0 -0
  109. {claude_mpm-4.1.8.dist-info → claude_mpm-4.1.11.dist-info}/entry_points.txt +0 -0
  110. {claude_mpm-4.1.8.dist-info → claude_mpm-4.1.11.dist-info}/licenses/LICENSE +0 -0
  111. {claude_mpm-4.1.8.dist-info → claude_mpm-4.1.11.dist-info}/top_level.txt +0 -0
@@ -58,7 +58,7 @@ class AgentConfig:
58
58
  """Agent configuration model matching the existing implementation."""
59
59
 
60
60
  def __init__(
61
- self, name: str, description: str = "", dependencies: List[str] = None
61
+ self, name: str, description: str = "", dependencies: Optional[List[str]] = None
62
62
  ):
63
63
  self.name = name
64
64
  self.description = description
@@ -123,7 +123,7 @@ class SimpleAgentManager:
123
123
 
124
124
  agent_id = template_data.get("agent_id", template_file.stem)
125
125
  metadata = template_data.get("metadata", {})
126
- name = metadata.get("name", agent_id)
126
+ metadata.get("name", agent_id)
127
127
  description = metadata.get(
128
128
  "description", "No description available"
129
129
  )
@@ -225,8 +225,8 @@ class AgentInfo:
225
225
  template_path: Path,
226
226
  description: str = "",
227
227
  version: str = "1.0.0",
228
- tools: List[str] = None,
229
- model: str = None,
228
+ tools: Optional[List[str]] = None,
229
+ model: Optional[str] = None,
230
230
  ):
231
231
  self.name = name
232
232
  self.category = category # "system", "project", "user"
@@ -1290,7 +1290,7 @@ class ConfigureTUI(App):
1290
1290
  Container {
1291
1291
  background: $surface;
1292
1292
  }
1293
-
1293
+
1294
1294
  #screen-title {
1295
1295
  text-style: bold;
1296
1296
  text-align: left;
@@ -1301,18 +1301,18 @@ class ConfigureTUI(App):
1301
1301
  margin-bottom: 1;
1302
1302
  border-bottom: solid $primary;
1303
1303
  }
1304
-
1304
+
1305
1305
  /* Header styles */
1306
1306
  Header {
1307
1307
  background: $primary;
1308
1308
  border-bottom: solid $accent;
1309
1309
  }
1310
-
1310
+
1311
1311
  /* Main layout */
1312
1312
  #main-layout {
1313
1313
  height: 100%;
1314
1314
  }
1315
-
1315
+
1316
1316
  /* Sidebar navigation - Clean minimal style */
1317
1317
  #sidebar {
1318
1318
  width: 25;
@@ -1320,7 +1320,7 @@ class ConfigureTUI(App):
1320
1320
  border-right: solid $primary;
1321
1321
  padding: 0;
1322
1322
  }
1323
-
1323
+
1324
1324
  .sidebar-title {
1325
1325
  text-style: bold;
1326
1326
  padding: 0 1;
@@ -1330,13 +1330,13 @@ class ConfigureTUI(App):
1330
1330
  margin-bottom: 0;
1331
1331
  border-bottom: solid $primary;
1332
1332
  }
1333
-
1333
+
1334
1334
  #nav-list {
1335
1335
  height: 100%;
1336
1336
  padding: 0;
1337
1337
  margin: 0;
1338
1338
  }
1339
-
1339
+
1340
1340
  /* Single-line list items with minimal styling */
1341
1341
  #nav-list > ListItem {
1342
1342
  padding: 0 2;
@@ -1344,49 +1344,49 @@ class ConfigureTUI(App):
1344
1344
  height: 1; /* Single line height */
1345
1345
  background: transparent;
1346
1346
  }
1347
-
1347
+
1348
1348
  #nav-list > ListItem Label {
1349
1349
  padding: 0;
1350
1350
  margin: 0;
1351
1351
  width: 100%;
1352
1352
  }
1353
-
1353
+
1354
1354
  /* Hover state - light background */
1355
1355
  #nav-list > ListItem:hover {
1356
1356
  background: $boost;
1357
1357
  }
1358
-
1358
+
1359
1359
  /* Highlighted/Selected state - accent background */
1360
1360
  #nav-list > ListItem.--highlight {
1361
1361
  background: $accent 30%;
1362
1362
  text-style: bold;
1363
1363
  }
1364
-
1364
+
1365
1365
  /* Active selected state - primary background with bold text */
1366
1366
  #nav-list > ListItem.active {
1367
1367
  background: $primary 50%;
1368
1368
  text-style: bold;
1369
1369
  }
1370
-
1370
+
1371
1371
  /* Main content area */
1372
1372
  #content-switcher {
1373
1373
  padding: 1;
1374
1374
  height: 100%;
1375
1375
  width: 100%;
1376
1376
  }
1377
-
1377
+
1378
1378
  /* Content screens (Containers) */
1379
1379
  #agents, #templates, #behaviors, #settings {
1380
1380
  height: 100%;
1381
1381
  width: 100%;
1382
1382
  }
1383
-
1383
+
1384
1384
  /* Agent Management simplified layout styles */
1385
1385
  #agent-management-screen {
1386
1386
  height: 100%;
1387
1387
  padding: 1;
1388
1388
  }
1389
-
1389
+
1390
1390
  #screen-title {
1391
1391
  text-style: bold;
1392
1392
  padding: 0 1;
@@ -1396,7 +1396,7 @@ class ConfigureTUI(App):
1396
1396
  margin-bottom: 1;
1397
1397
  border-bottom: solid $primary;
1398
1398
  }
1399
-
1399
+
1400
1400
  /* Compact headers for all screens */
1401
1401
  #list-title, #viewer-title, #tree-title, #editor-title {
1402
1402
  text-style: bold;
@@ -1407,44 +1407,44 @@ class ConfigureTUI(App):
1407
1407
  margin-bottom: 1;
1408
1408
  border-bottom: solid $primary;
1409
1409
  }
1410
-
1410
+
1411
1411
  #agent-search {
1412
1412
  margin-bottom: 1;
1413
1413
  width: 100%;
1414
1414
  }
1415
-
1415
+
1416
1416
  #agent-list-table {
1417
1417
  height: 20;
1418
1418
  min-height: 15;
1419
1419
  margin-bottom: 1;
1420
1420
  border: solid $primary;
1421
1421
  }
1422
-
1422
+
1423
1423
  #agent-details {
1424
1424
  padding: 1;
1425
1425
  height: 10;
1426
1426
  border: solid $primary;
1427
1427
  margin-bottom: 1;
1428
1428
  }
1429
-
1429
+
1430
1430
  #agent-action-buttons {
1431
1431
  height: 3;
1432
1432
  align: center middle;
1433
1433
  }
1434
-
1434
+
1435
1435
  #agent-action-buttons Button {
1436
1436
  margin: 0 1;
1437
1437
  }
1438
-
1438
+
1439
1439
  #agent-category-tabs {
1440
1440
  height: 3;
1441
1441
  margin-bottom: 1;
1442
1442
  }
1443
-
1443
+
1444
1444
  #agent-category-tabs TabPane {
1445
1445
  padding: 0;
1446
1446
  }
1447
-
1447
+
1448
1448
  #view-properties-dialog {
1449
1449
  align: center middle;
1450
1450
  background: $panel;
@@ -1454,96 +1454,96 @@ class ConfigureTUI(App):
1454
1454
  width: 90%;
1455
1455
  height: 80%;
1456
1456
  }
1457
-
1457
+
1458
1458
  #properties-title {
1459
1459
  text-style: bold;
1460
1460
  margin-bottom: 1;
1461
1461
  }
1462
-
1462
+
1463
1463
  #properties-viewer {
1464
1464
  width: 100%;
1465
1465
  height: 100%;
1466
1466
  margin: 1 0;
1467
1467
  }
1468
-
1468
+
1469
1469
  #properties-buttons {
1470
1470
  align: center middle;
1471
1471
  height: 3;
1472
1472
  margin-top: 1;
1473
1473
  }
1474
-
1474
+
1475
1475
  /* Template screen styles */
1476
1476
  #template-layout {
1477
1477
  height: 100%;
1478
1478
  }
1479
-
1479
+
1480
1480
  #template-list-container {
1481
1481
  width: 40%;
1482
1482
  border-right: solid $primary;
1483
1483
  padding-right: 1;
1484
1484
  }
1485
-
1485
+
1486
1486
  #template-viewer-container {
1487
1487
  width: 60%;
1488
1488
  padding-left: 1;
1489
1489
  }
1490
-
1490
+
1491
1491
  #template-viewer {
1492
1492
  height: 100%;
1493
1493
  }
1494
-
1494
+
1495
1495
  #template-actions {
1496
1496
  align: center middle;
1497
1497
  height: 3;
1498
1498
  margin-top: 1;
1499
1499
  }
1500
-
1500
+
1501
1501
  #template-actions Button {
1502
1502
  margin: 0 1;
1503
1503
  }
1504
-
1504
+
1505
1505
  /* Behavior screen styles */
1506
1506
  #behavior-layout {
1507
1507
  height: 100%;
1508
1508
  }
1509
-
1509
+
1510
1510
  #file-tree-container {
1511
1511
  width: 30%;
1512
1512
  border-right: solid $primary;
1513
1513
  padding-right: 1;
1514
1514
  }
1515
-
1515
+
1516
1516
  #file-editor-container {
1517
1517
  width: 70%;
1518
1518
  padding-left: 1;
1519
1519
  }
1520
-
1520
+
1521
1521
  #behavior-editor {
1522
1522
  height: 100%;
1523
1523
  }
1524
-
1524
+
1525
1525
  #behavior-actions {
1526
1526
  align: center middle;
1527
1527
  height: 3;
1528
1528
  margin-top: 1;
1529
1529
  }
1530
-
1530
+
1531
1531
  #behavior-actions Button {
1532
1532
  margin: 0 1;
1533
1533
  }
1534
-
1534
+
1535
1535
  /* Settings screen styles */
1536
1536
  #settings-content {
1537
1537
  padding: 2;
1538
1538
  max-width: 80;
1539
1539
  }
1540
-
1540
+
1541
1541
  .settings-section {
1542
1542
  margin-bottom: 2;
1543
1543
  border: solid $primary;
1544
1544
  padding: 1;
1545
1545
  }
1546
-
1546
+
1547
1547
  .section-title {
1548
1548
  text-style: bold;
1549
1549
  padding: 0 1;
@@ -1552,26 +1552,26 @@ class ConfigureTUI(App):
1552
1552
  color: $primary;
1553
1553
  border-bottom: solid $primary;
1554
1554
  }
1555
-
1555
+
1556
1556
  .setting-row {
1557
1557
  align: left middle;
1558
1558
  height: 3;
1559
1559
  }
1560
-
1560
+
1561
1561
  .setting-label {
1562
1562
  width: 20;
1563
1563
  }
1564
-
1564
+
1565
1565
  .setting-value {
1566
1566
  width: 40;
1567
1567
  color: $text-muted;
1568
1568
  }
1569
-
1569
+
1570
1570
  .version-line {
1571
1571
  padding: 0 1;
1572
1572
  margin: 0;
1573
1573
  }
1574
-
1574
+
1575
1575
  /* Modal dialog styles */
1576
1576
  #confirm-dialog, #edit-dialog {
1577
1577
  align: center middle;
@@ -1580,31 +1580,31 @@ class ConfigureTUI(App):
1580
1580
  padding: 2;
1581
1581
  margin: 4 8;
1582
1582
  }
1583
-
1583
+
1584
1584
  #confirm-title, #edit-title {
1585
1585
  text-style: bold;
1586
1586
  margin-bottom: 1;
1587
1587
  }
1588
-
1588
+
1589
1589
  #confirm-message {
1590
1590
  margin-bottom: 2;
1591
1591
  }
1592
-
1592
+
1593
1593
  #confirm-buttons, #edit-buttons {
1594
1594
  align: center middle;
1595
1595
  height: 3;
1596
1596
  }
1597
-
1597
+
1598
1598
  #confirm-buttons Button, #edit-buttons Button {
1599
1599
  margin: 0 1;
1600
1600
  }
1601
-
1601
+
1602
1602
  #template-editor {
1603
1603
  width: 80;
1604
1604
  height: 30;
1605
1605
  margin: 1 0;
1606
1606
  }
1607
-
1607
+
1608
1608
  /* Footer styles */
1609
1609
  Footer {
1610
1610
  background: $panel;
@@ -1623,7 +1623,9 @@ class ConfigureTUI(App):
1623
1623
  Binding("ctrl+left", "focus_prev_pane", "Prev Pane", show=False),
1624
1624
  ]
1625
1625
 
1626
- def __init__(self, current_scope: str = "project", project_dir: Path = None):
1626
+ def __init__(
1627
+ self, current_scope: str = "project", project_dir: Optional[Path] = None
1628
+ ):
1627
1629
  super().__init__()
1628
1630
  self.current_scope = current_scope
1629
1631
  self.project_dir = project_dir or Path.cwd()
@@ -1644,7 +1646,7 @@ class ConfigureTUI(App):
1644
1646
  def compose(self) -> ComposeResult:
1645
1647
  """Create the main application layout."""
1646
1648
  # Header with version info
1647
- mpm_version = self.version_service.get_version()
1649
+ self.version_service.get_version()
1648
1650
  yield Header(show_clock=True)
1649
1651
  yield Rule(line_style="heavy")
1650
1652
 
@@ -1912,7 +1914,7 @@ def can_use_tui() -> bool:
1912
1914
 
1913
1915
 
1914
1916
  def launch_tui(
1915
- current_scope: str = "project", project_dir: Path = None
1917
+ current_scope: str = "project", project_dir: Optional[Path] = None
1916
1918
  ) -> CommandResult:
1917
1919
  """Launch the Textual TUI application."""
1918
1920
  try:
@@ -0,0 +1,288 @@
1
+ """
2
+ Dashboard command implementation for claude-mpm.
3
+
4
+ WHY: This module provides CLI commands for managing the web dashboard interface,
5
+ allowing users to start, stop, check status, and open the dashboard in a browser.
6
+
7
+ DESIGN DECISIONS:
8
+ - Use DashboardLauncher service for consistent dashboard management
9
+ - Support both foreground and background operation modes
10
+ - Integrate with SocketIO server for real-time event streaming
11
+ - Provide browser auto-opening functionality
12
+ """
13
+
14
+ import signal
15
+ import sys
16
+ import time
17
+ from typing import Optional
18
+
19
+ from ...constants import DashboardCommands
20
+ from ...services.cli.dashboard_launcher import DashboardLauncher
21
+ from ...services.port_manager import PortManager
22
+ from ...services.socketio.server.main import SocketIOServer
23
+ from ..shared import BaseCommand, CommandResult
24
+
25
+
26
+ class DashboardCommand(BaseCommand):
27
+ """Dashboard command for managing the web dashboard interface."""
28
+
29
+ def __init__(self):
30
+ super().__init__("dashboard")
31
+ self.dashboard_launcher = DashboardLauncher(self.logger)
32
+ self.port_manager = PortManager()
33
+ self.server = None
34
+
35
+ def validate_args(self, args) -> Optional[str]:
36
+ """Validate command arguments."""
37
+ if hasattr(args, "dashboard_command") and args.dashboard_command:
38
+ valid_commands = [cmd.value for cmd in DashboardCommands]
39
+ if args.dashboard_command not in valid_commands:
40
+ return f"Unknown dashboard command: {args.dashboard_command}. Valid commands: {', '.join(valid_commands)}"
41
+ return None
42
+
43
+ def run(self, args) -> CommandResult:
44
+ """Execute the dashboard command."""
45
+ try:
46
+ # Handle default case (no subcommand) - default to status
47
+ if not hasattr(args, "dashboard_command") or not args.dashboard_command:
48
+ return self._status_dashboard(args)
49
+
50
+ # Route to specific subcommand handlers
51
+ command_map = {
52
+ DashboardCommands.START.value: self._start_dashboard,
53
+ DashboardCommands.STOP.value: self._stop_dashboard,
54
+ DashboardCommands.STATUS.value: self._status_dashboard,
55
+ DashboardCommands.OPEN.value: self._open_dashboard,
56
+ }
57
+
58
+ if args.dashboard_command in command_map:
59
+ return command_map[args.dashboard_command](args)
60
+
61
+ return CommandResult.error_result(
62
+ f"Unknown dashboard command: {args.dashboard_command}"
63
+ )
64
+
65
+ except Exception as e:
66
+ self.logger.error(f"Error executing dashboard command: {e}", exc_info=True)
67
+ return CommandResult.error_result(f"Error executing dashboard command: {e}")
68
+
69
+ def _start_dashboard(self, args) -> CommandResult:
70
+ """Start the dashboard server."""
71
+ port = getattr(args, "port", 8765)
72
+ host = getattr(args, "host", "localhost")
73
+ background = getattr(args, "background", False)
74
+
75
+ self.logger.info(
76
+ f"Starting dashboard on {host}:{port} (background: {background})"
77
+ )
78
+
79
+ # Check if dashboard is already running
80
+ if self.dashboard_launcher.is_dashboard_running(port):
81
+ dashboard_url = self.dashboard_launcher.get_dashboard_url(port)
82
+ return CommandResult.success_result(
83
+ f"Dashboard already running at {dashboard_url}",
84
+ data={"url": dashboard_url, "port": port},
85
+ )
86
+
87
+ if background:
88
+ # Use the dashboard launcher for background mode
89
+ success, browser_opened = self.dashboard_launcher.launch_dashboard(
90
+ port=port, monitor_mode=True
91
+ )
92
+ if success:
93
+ dashboard_url = self.dashboard_launcher.get_dashboard_url(port)
94
+ return CommandResult.success_result(
95
+ f"Dashboard started at {dashboard_url}",
96
+ data={
97
+ "url": dashboard_url,
98
+ "port": port,
99
+ "browser_opened": browser_opened,
100
+ },
101
+ )
102
+ return CommandResult.error_result("Failed to start dashboard in background")
103
+ # Run in foreground mode - directly start the SocketIO server
104
+ try:
105
+ print(f"Starting dashboard server on {host}:{port}...")
106
+ print("Press Ctrl+C to stop the server")
107
+
108
+ # Create and start the SocketIO server
109
+ self.server = SocketIOServer(host=host, port=port)
110
+
111
+ # Set up signal handlers for graceful shutdown
112
+ def signal_handler(signum, frame):
113
+ print("\nShutting down dashboard server...")
114
+ if self.server:
115
+ self.server.stop_sync()
116
+ sys.exit(0)
117
+
118
+ signal.signal(signal.SIGINT, signal_handler)
119
+ signal.signal(signal.SIGTERM, signal_handler)
120
+
121
+ # Start the server (this starts in background thread)
122
+ self.server.start_sync()
123
+
124
+ # Keep the main thread alive while server is running
125
+ # The server runs in a background thread, so we need to block here
126
+ try:
127
+ while self.server.is_running():
128
+ time.sleep(1)
129
+ except KeyboardInterrupt:
130
+ # Ctrl+C pressed, stop the server
131
+ pass
132
+
133
+ # Server has stopped or user interrupted
134
+ if self.server:
135
+ self.server.stop_sync()
136
+
137
+ return CommandResult.success_result("Dashboard server stopped")
138
+
139
+ except KeyboardInterrupt:
140
+ print("\nDashboard server stopped by user")
141
+ return CommandResult.success_result("Dashboard server stopped")
142
+ except Exception as e:
143
+ return CommandResult.error_result(f"Failed to start dashboard: {e}")
144
+
145
+ def _stop_dashboard(self, args) -> CommandResult:
146
+ """Stop the dashboard server."""
147
+ port = getattr(args, "port", 8765)
148
+
149
+ self.logger.info(f"Stopping dashboard on port {port}")
150
+
151
+ if not self.dashboard_launcher.is_dashboard_running(port):
152
+ return CommandResult.success_result(f"No dashboard running on port {port}")
153
+
154
+ if self.dashboard_launcher.stop_dashboard(port):
155
+ return CommandResult.success_result(f"Dashboard stopped on port {port}")
156
+
157
+ return CommandResult.error_result(f"Failed to stop dashboard on port {port}")
158
+
159
+ def _status_dashboard(self, args) -> CommandResult:
160
+ """Check dashboard server status."""
161
+ verbose = getattr(args, "verbose", False)
162
+ show_ports = getattr(args, "show_ports", False)
163
+
164
+ # Check default port first
165
+ default_port = 8765
166
+ dashboard_running = self.dashboard_launcher.is_dashboard_running(default_port)
167
+
168
+ status_data = {
169
+ "running": dashboard_running,
170
+ "default_port": default_port,
171
+ }
172
+
173
+ if dashboard_running:
174
+ status_data["url"] = self.dashboard_launcher.get_dashboard_url(default_port)
175
+
176
+ # Check all ports if requested
177
+ if show_ports:
178
+ port_status = {}
179
+ for port in range(8765, 8786):
180
+ is_running = self.dashboard_launcher.is_dashboard_running(port)
181
+ port_status[port] = {
182
+ "running": is_running,
183
+ "url": (
184
+ self.dashboard_launcher.get_dashboard_url(port)
185
+ if is_running
186
+ else None
187
+ ),
188
+ }
189
+ status_data["ports"] = port_status
190
+
191
+ # Get active instances from port manager
192
+ self.port_manager.cleanup_dead_instances()
193
+ active_instances = self.port_manager.list_active_instances()
194
+ if active_instances:
195
+ status_data["active_instances"] = active_instances
196
+
197
+ if verbose:
198
+ # Add more detailed information
199
+ import socket
200
+
201
+ status_data["hostname"] = socket.gethostname()
202
+ status_data["can_bind"] = self._check_port_available(default_port)
203
+
204
+ # Format output message
205
+ if dashboard_running:
206
+ message = f"Dashboard is running at {status_data['url']}"
207
+ else:
208
+ message = "Dashboard is not running"
209
+
210
+ return CommandResult.success_result(message, data=status_data)
211
+
212
+ def _open_dashboard(self, args) -> CommandResult:
213
+ """Open the dashboard in a browser, starting it if necessary."""
214
+ port = getattr(args, "port", 8765)
215
+
216
+ # Check if dashboard is running
217
+ if not self.dashboard_launcher.is_dashboard_running(port):
218
+ self.logger.info("Dashboard not running, starting it first...")
219
+ # Start dashboard in background
220
+ success, browser_opened = self.dashboard_launcher.launch_dashboard(
221
+ port=port, monitor_mode=True
222
+ )
223
+ if success:
224
+ dashboard_url = self.dashboard_launcher.get_dashboard_url(port)
225
+ return CommandResult.success_result(
226
+ f"Dashboard started and opened at {dashboard_url}",
227
+ data={
228
+ "url": dashboard_url,
229
+ "port": port,
230
+ "browser_opened": browser_opened,
231
+ },
232
+ )
233
+ return CommandResult.error_result("Failed to start and open dashboard")
234
+ # Dashboard already running, just open browser
235
+ dashboard_url = self.dashboard_launcher.get_dashboard_url(port)
236
+ if self.dashboard_launcher._open_browser(dashboard_url):
237
+ return CommandResult.success_result(
238
+ f"Opened dashboard at {dashboard_url}",
239
+ data={"url": dashboard_url, "port": port},
240
+ )
241
+ return CommandResult.success_result(
242
+ f"Dashboard running at {dashboard_url} (could not auto-open browser)",
243
+ data={"url": dashboard_url, "port": port},
244
+ )
245
+
246
+ def _check_port_available(self, port: int) -> bool:
247
+ """Check if a port is available for binding."""
248
+ import socket
249
+
250
+ try:
251
+ with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
252
+ s.bind(("", port))
253
+ return True
254
+ except OSError:
255
+ return False
256
+
257
+
258
+ def manage_dashboard(args) -> int:
259
+ """
260
+ Main entry point for dashboard command.
261
+
262
+ Args:
263
+ args: Parsed command line arguments
264
+
265
+ Returns:
266
+ Exit code (0 for success, non-zero for error)
267
+ """
268
+ command = DashboardCommand()
269
+ error = command.validate_args(args)
270
+
271
+ if error:
272
+ command.logger.error(error)
273
+ print(f"Error: {error}")
274
+ return 1
275
+
276
+ result = command.run(args)
277
+
278
+ if result.success:
279
+ if result.message:
280
+ print(result.message)
281
+ if result.data and getattr(args, "verbose", False):
282
+ import json
283
+
284
+ print(json.dumps(result.data, indent=2))
285
+ return 0
286
+ if result.message:
287
+ print(f"Error: {result.message}")
288
+ return 1