claude-mpm 4.12.4__py3-none-any.whl → 4.13.1__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.
- claude_mpm/VERSION +1 -1
- claude_mpm/cli/__init__.py +10 -0
- claude_mpm/cli/commands/agents.py +31 -0
- claude_mpm/cli/commands/agents_detect.py +380 -0
- claude_mpm/cli/commands/agents_recommend.py +309 -0
- claude_mpm/cli/commands/auto_configure.py +572 -0
- claude_mpm/cli/parsers/agents_parser.py +9 -0
- claude_mpm/cli/parsers/auto_configure_parser.py +245 -0
- claude_mpm/cli/parsers/base_parser.py +7 -0
- claude_mpm/services/agents/__init__.py +18 -5
- claude_mpm/services/agents/auto_config_manager.py +797 -0
- claude_mpm/services/agents/observers.py +547 -0
- claude_mpm/services/agents/recommender.py +568 -0
- claude_mpm/services/core/__init__.py +33 -1
- claude_mpm/services/core/interfaces/__init__.py +16 -1
- claude_mpm/services/core/interfaces/agent.py +184 -0
- claude_mpm/services/core/interfaces/project.py +121 -0
- claude_mpm/services/core/models/__init__.py +46 -0
- claude_mpm/services/core/models/agent_config.py +397 -0
- claude_mpm/services/core/models/toolchain.py +306 -0
- claude_mpm/services/project/__init__.py +23 -0
- claude_mpm/services/project/detection_strategies.py +719 -0
- claude_mpm/services/project/toolchain_analyzer.py +581 -0
- {claude_mpm-4.12.4.dist-info → claude_mpm-4.13.1.dist-info}/METADATA +1 -1
- {claude_mpm-4.12.4.dist-info → claude_mpm-4.13.1.dist-info}/RECORD +29 -16
- {claude_mpm-4.12.4.dist-info → claude_mpm-4.13.1.dist-info}/WHEEL +0 -0
- {claude_mpm-4.12.4.dist-info → claude_mpm-4.13.1.dist-info}/entry_points.txt +0 -0
- {claude_mpm-4.12.4.dist-info → claude_mpm-4.13.1.dist-info}/licenses/LICENSE +0 -0
- {claude_mpm-4.12.4.dist-info → claude_mpm-4.13.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Agents Recommend CLI Command for Claude MPM Framework
|
|
3
|
+
======================================================
|
|
4
|
+
|
|
5
|
+
WHY: This module provides a CLI interface for getting agent recommendations
|
|
6
|
+
based on project toolchain without deploying anything. Useful for reviewing
|
|
7
|
+
recommendations before committing to deployment.
|
|
8
|
+
|
|
9
|
+
DESIGN DECISION: Focused on recommendation display with detailed reasoning,
|
|
10
|
+
showing users why each agent was recommended. Supports JSON output for
|
|
11
|
+
integration with other tools.
|
|
12
|
+
|
|
13
|
+
Part of TSK-0054: Auto-Configuration Feature - Phase 5
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Optional
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
from rich.console import Console
|
|
22
|
+
from rich.panel import Panel
|
|
23
|
+
from rich.table import Table
|
|
24
|
+
|
|
25
|
+
RICH_AVAILABLE = True
|
|
26
|
+
except ImportError:
|
|
27
|
+
RICH_AVAILABLE = False
|
|
28
|
+
|
|
29
|
+
from ...services.agents.recommender import AgentRecommenderService
|
|
30
|
+
from ...services.agents.registry import AgentRegistry
|
|
31
|
+
from ...services.project.toolchain_analyzer import ToolchainAnalyzerService
|
|
32
|
+
from ..shared import BaseCommand, CommandResult
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class AgentsRecommendCommand(BaseCommand):
|
|
36
|
+
"""
|
|
37
|
+
Handle agents recommend CLI command.
|
|
38
|
+
|
|
39
|
+
This command analyzes the project toolchain and recommends appropriate
|
|
40
|
+
agents without deploying them. Shows detailed reasoning for each
|
|
41
|
+
recommendation.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
def __init__(self):
|
|
45
|
+
"""Initialize the agents recommend command."""
|
|
46
|
+
super().__init__("agents-recommend")
|
|
47
|
+
self.console = Console() if RICH_AVAILABLE else None
|
|
48
|
+
self._toolchain_analyzer = None
|
|
49
|
+
self._agent_recommender = None
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def toolchain_analyzer(self) -> ToolchainAnalyzerService:
|
|
53
|
+
"""Get toolchain analyzer (lazy loaded)."""
|
|
54
|
+
if self._toolchain_analyzer is None:
|
|
55
|
+
self._toolchain_analyzer = ToolchainAnalyzerService()
|
|
56
|
+
return self._toolchain_analyzer
|
|
57
|
+
|
|
58
|
+
@property
|
|
59
|
+
def agent_recommender(self) -> AgentRecommenderService:
|
|
60
|
+
"""Get agent recommender (lazy loaded)."""
|
|
61
|
+
if self._agent_recommender is None:
|
|
62
|
+
agent_registry = AgentRegistry()
|
|
63
|
+
self._agent_recommender = AgentRecommenderService(
|
|
64
|
+
agent_registry=agent_registry
|
|
65
|
+
)
|
|
66
|
+
return self._agent_recommender
|
|
67
|
+
|
|
68
|
+
def validate_args(self, args) -> Optional[str]:
|
|
69
|
+
"""Validate command arguments."""
|
|
70
|
+
# Validate project path
|
|
71
|
+
project_path = (
|
|
72
|
+
Path(args.project_path)
|
|
73
|
+
if hasattr(args, "project_path") and args.project_path
|
|
74
|
+
else Path.cwd()
|
|
75
|
+
)
|
|
76
|
+
if not project_path.exists():
|
|
77
|
+
return f"Project path does not exist: {project_path}"
|
|
78
|
+
|
|
79
|
+
# Validate min_confidence range
|
|
80
|
+
if hasattr(args, "min_confidence") and args.min_confidence:
|
|
81
|
+
if not 0.0 <= args.min_confidence <= 1.0:
|
|
82
|
+
return "min_confidence must be between 0.0 and 1.0"
|
|
83
|
+
|
|
84
|
+
return None
|
|
85
|
+
|
|
86
|
+
def run(self, args) -> CommandResult:
|
|
87
|
+
"""
|
|
88
|
+
Execute agents recommend command.
|
|
89
|
+
|
|
90
|
+
Returns:
|
|
91
|
+
CommandResult with success status and exit code
|
|
92
|
+
"""
|
|
93
|
+
try:
|
|
94
|
+
# Setup logging
|
|
95
|
+
self.setup_logging(args)
|
|
96
|
+
|
|
97
|
+
# Validate arguments
|
|
98
|
+
error = self.validate_args(args)
|
|
99
|
+
if error:
|
|
100
|
+
return CommandResult.error_result(error)
|
|
101
|
+
|
|
102
|
+
# Get configuration options
|
|
103
|
+
project_path = (
|
|
104
|
+
Path(args.project_path)
|
|
105
|
+
if hasattr(args, "project_path") and args.project_path
|
|
106
|
+
else Path.cwd()
|
|
107
|
+
)
|
|
108
|
+
min_confidence = (
|
|
109
|
+
args.min_confidence
|
|
110
|
+
if hasattr(args, "min_confidence") and args.min_confidence
|
|
111
|
+
else 0.8
|
|
112
|
+
)
|
|
113
|
+
json_output = args.json if hasattr(args, "json") and args.json else False
|
|
114
|
+
show_reasoning = (
|
|
115
|
+
args.show_reasoning
|
|
116
|
+
if hasattr(args, "show_reasoning") and args.show_reasoning
|
|
117
|
+
else True
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
# Analyze toolchain
|
|
121
|
+
if self.console and not json_output:
|
|
122
|
+
with self.console.status("[bold green]Analyzing project toolchain..."):
|
|
123
|
+
analysis = self.toolchain_analyzer.analyze_project(
|
|
124
|
+
str(project_path)
|
|
125
|
+
)
|
|
126
|
+
else:
|
|
127
|
+
analysis = self.toolchain_analyzer.analyze_project(str(project_path))
|
|
128
|
+
|
|
129
|
+
# Get recommendations
|
|
130
|
+
if self.console and not json_output:
|
|
131
|
+
with self.console.status(
|
|
132
|
+
"[bold green]Generating agent recommendations..."
|
|
133
|
+
):
|
|
134
|
+
recommendations = self.agent_recommender.recommend_agents(
|
|
135
|
+
analysis, min_confidence
|
|
136
|
+
)
|
|
137
|
+
else:
|
|
138
|
+
recommendations = self.agent_recommender.recommend_agents(
|
|
139
|
+
analysis, min_confidence
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
# Output results
|
|
143
|
+
if json_output:
|
|
144
|
+
return self._output_json(recommendations, analysis)
|
|
145
|
+
return self._display_results(recommendations, analysis, show_reasoning)
|
|
146
|
+
|
|
147
|
+
except KeyboardInterrupt:
|
|
148
|
+
if self.console:
|
|
149
|
+
self.console.print("\n\n❌ Operation cancelled by user")
|
|
150
|
+
else:
|
|
151
|
+
print("\n\nOperation cancelled by user")
|
|
152
|
+
return CommandResult.error_result("Operation cancelled", exit_code=130)
|
|
153
|
+
|
|
154
|
+
except Exception as e:
|
|
155
|
+
self.logger.exception("Agent recommendation failed")
|
|
156
|
+
error_msg = f"Agent recommendation failed: {e!s}"
|
|
157
|
+
if self.console:
|
|
158
|
+
self.console.print(f"\n❌ {error_msg}")
|
|
159
|
+
else:
|
|
160
|
+
print(f"\n{error_msg}")
|
|
161
|
+
return CommandResult.error_result(error_msg)
|
|
162
|
+
|
|
163
|
+
def _display_results(
|
|
164
|
+
self, recommendations, analysis, show_reasoning: bool
|
|
165
|
+
) -> CommandResult:
|
|
166
|
+
"""Display agent recommendations with Rich formatting."""
|
|
167
|
+
if not self.console:
|
|
168
|
+
return self._display_results_plain(
|
|
169
|
+
recommendations, analysis, show_reasoning
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
# Display header
|
|
173
|
+
self.console.print("\n🤖 Agent Recommendations", style="bold blue")
|
|
174
|
+
self.console.print(f"Project: {analysis.project_path}\n")
|
|
175
|
+
|
|
176
|
+
# Display quick summary
|
|
177
|
+
if recommendations:
|
|
178
|
+
summary_text = (
|
|
179
|
+
f"Found {len(recommendations)} recommended agent(s) "
|
|
180
|
+
f"for your project based on detected toolchain."
|
|
181
|
+
)
|
|
182
|
+
panel = Panel(summary_text, border_style="green")
|
|
183
|
+
self.console.print(panel)
|
|
184
|
+
else:
|
|
185
|
+
panel = Panel(
|
|
186
|
+
"No agents recommended for this project.\n"
|
|
187
|
+
"Try lowering the confidence threshold with --min-confidence",
|
|
188
|
+
border_style="yellow",
|
|
189
|
+
)
|
|
190
|
+
self.console.print(panel)
|
|
191
|
+
return CommandResult.success_result()
|
|
192
|
+
|
|
193
|
+
# Display recommendations table
|
|
194
|
+
self.console.print("\n📋 Recommended Agents:", style="bold green")
|
|
195
|
+
table = Table(show_header=True, header_style="bold")
|
|
196
|
+
table.add_column("Agent ID", style="cyan")
|
|
197
|
+
table.add_column("Confidence", style="green")
|
|
198
|
+
table.add_column("Priority", style="yellow")
|
|
199
|
+
if show_reasoning:
|
|
200
|
+
table.add_column("Reasoning", style="dim", no_wrap=False)
|
|
201
|
+
|
|
202
|
+
for rec in recommendations:
|
|
203
|
+
confidence_pct = int(rec.confidence * 100)
|
|
204
|
+
bar = "█" * (confidence_pct // 10) + "░" * (10 - confidence_pct // 10)
|
|
205
|
+
confidence_str = f"{bar} {confidence_pct}%"
|
|
206
|
+
|
|
207
|
+
if show_reasoning:
|
|
208
|
+
table.add_row(
|
|
209
|
+
rec.agent_id,
|
|
210
|
+
confidence_str,
|
|
211
|
+
str(rec.priority),
|
|
212
|
+
rec.reasoning,
|
|
213
|
+
)
|
|
214
|
+
else:
|
|
215
|
+
table.add_row(rec.agent_id, confidence_str, str(rec.priority))
|
|
216
|
+
|
|
217
|
+
self.console.print(table)
|
|
218
|
+
|
|
219
|
+
# Display match details if reasoning enabled
|
|
220
|
+
if show_reasoning:
|
|
221
|
+
self.console.print("\n🔍 Match Details:", style="bold blue")
|
|
222
|
+
for rec in recommendations:
|
|
223
|
+
self.console.print(f"\n[bold cyan]{rec.agent_id}[/bold cyan]")
|
|
224
|
+
self.console.print(f" Confidence: {int(rec.confidence * 100)}%")
|
|
225
|
+
self.console.print(f" Priority: {rec.priority}")
|
|
226
|
+
self.console.print(f" Reasoning: {rec.reasoning}")
|
|
227
|
+
|
|
228
|
+
if rec.matched_capabilities:
|
|
229
|
+
self.console.print(" Matched capabilities:", style="green")
|
|
230
|
+
for cap in rec.matched_capabilities[:5]:
|
|
231
|
+
self.console.print(f" • {cap}", style="dim")
|
|
232
|
+
if len(rec.matched_capabilities) > 5:
|
|
233
|
+
remaining = len(rec.matched_capabilities) - 5
|
|
234
|
+
self.console.print(f" ... and {remaining} more", style="dim")
|
|
235
|
+
|
|
236
|
+
# Display next steps
|
|
237
|
+
self.console.print("\n💡 Next Steps:", style="bold yellow")
|
|
238
|
+
self.console.print(" 1. Review the recommendations and their reasoning")
|
|
239
|
+
self.console.print(
|
|
240
|
+
" 2. Deploy agents with: [bold]claude-mpm auto-configure[/bold]"
|
|
241
|
+
)
|
|
242
|
+
self.console.print(
|
|
243
|
+
" 3. Or preview deployment with: [bold]claude-mpm auto-configure --preview[/bold]"
|
|
244
|
+
)
|
|
245
|
+
|
|
246
|
+
return CommandResult.success_result()
|
|
247
|
+
|
|
248
|
+
def _display_results_plain(
|
|
249
|
+
self, recommendations, analysis, show_reasoning: bool
|
|
250
|
+
) -> CommandResult:
|
|
251
|
+
"""Display results in plain text (fallback)."""
|
|
252
|
+
print("\n🤖 Agent Recommendations")
|
|
253
|
+
print(f"Project: {analysis.project_path}\n")
|
|
254
|
+
|
|
255
|
+
if not recommendations:
|
|
256
|
+
print("No agents recommended for this project.")
|
|
257
|
+
print("Try lowering the confidence threshold with --min-confidence")
|
|
258
|
+
return CommandResult.success_result()
|
|
259
|
+
|
|
260
|
+
print(f"Found {len(recommendations)} recommended agent(s) for your project:\n")
|
|
261
|
+
|
|
262
|
+
for rec in recommendations:
|
|
263
|
+
confidence_pct = int(rec.confidence * 100)
|
|
264
|
+
print(f"• {rec.agent_id} ({confidence_pct}% confidence)")
|
|
265
|
+
|
|
266
|
+
if show_reasoning:
|
|
267
|
+
print(f" Priority: {rec.priority}")
|
|
268
|
+
print(f" Reasoning: {rec.reasoning}")
|
|
269
|
+
|
|
270
|
+
if rec.matched_capabilities:
|
|
271
|
+
print(" Matched capabilities:")
|
|
272
|
+
for cap in rec.matched_capabilities[:5]:
|
|
273
|
+
print(f" - {cap}")
|
|
274
|
+
if len(rec.matched_capabilities) > 5:
|
|
275
|
+
remaining = len(rec.matched_capabilities) - 5
|
|
276
|
+
print(f" ... and {remaining} more")
|
|
277
|
+
print()
|
|
278
|
+
|
|
279
|
+
print("\nNext Steps:")
|
|
280
|
+
print(" 1. Review the recommendations and their reasoning")
|
|
281
|
+
print(" 2. Deploy agents with: claude-mpm auto-configure")
|
|
282
|
+
print(" 3. Or preview deployment with: claude-mpm auto-configure --preview")
|
|
283
|
+
|
|
284
|
+
return CommandResult.success_result()
|
|
285
|
+
|
|
286
|
+
def _output_json(self, recommendations, analysis) -> CommandResult:
|
|
287
|
+
"""Output recommendations as JSON."""
|
|
288
|
+
output = {
|
|
289
|
+
"project_path": analysis.project_path,
|
|
290
|
+
"recommendations": [
|
|
291
|
+
{
|
|
292
|
+
"agent_id": rec.agent_id,
|
|
293
|
+
"confidence": rec.confidence,
|
|
294
|
+
"priority": rec.priority,
|
|
295
|
+
"reasoning": rec.reasoning,
|
|
296
|
+
"matched_capabilities": rec.matched_capabilities,
|
|
297
|
+
"requirements": rec.requirements,
|
|
298
|
+
}
|
|
299
|
+
for rec in recommendations
|
|
300
|
+
],
|
|
301
|
+
"toolchain_summary": {
|
|
302
|
+
"languages": len(analysis.languages),
|
|
303
|
+
"frameworks": len(analysis.frameworks),
|
|
304
|
+
"deployment_targets": len(analysis.deployment_targets),
|
|
305
|
+
},
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
print(json.dumps(output, indent=2))
|
|
309
|
+
return CommandResult.success_result(data=output)
|