Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions cli/cli_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,37 +132,26 @@ def display_results(
print(f"{Colors.BOLD}{Colors.OKCYAN}📊 ANALYSIS PHASE RESULTS:{Colors.ENDC}")
self.cli.print_separator("─", 79, Colors.CYAN)

# 尝试解析并格式化分析结果
# Results are pre-truncated by workflow_adapter, so display directly
# Only attempt JSON parsing/formatting for structured data
try:
if analysis_result.strip().startswith("{"):
parsed_analysis = json.loads(analysis_result)
print(json.dumps(parsed_analysis, indent=2, ensure_ascii=False))
else:
print(
analysis_result[:1000] + "..."
if len(analysis_result) > 1000
else analysis_result
)
print(analysis_result)
except Exception:
print(
analysis_result[:1000] + "..."
if len(analysis_result) > 1000
else analysis_result
)
print(analysis_result)

print(f"\n{Colors.BOLD}{Colors.PURPLE}📥 DOWNLOAD PHASE RESULTS:{Colors.ENDC}")
self.cli.print_separator("─", 79, Colors.PURPLE)
print(
download_result[:1000] + "..."
if len(download_result) > 1000
else download_result
)
print(download_result)

print(
f"\n{Colors.BOLD}{Colors.GREEN}⚙️ IMPLEMENTATION PHASE RESULTS:{Colors.ENDC}"
)
self.cli.print_separator("─", 79, Colors.GREEN)
print(repo_result[:1000] + "..." if len(repo_result) > 1000 else repo_result)
print(repo_result)

# 尝试提取生成的代码目录信息
if "Code generated in:" in repo_result:
Expand Down
64 changes: 60 additions & 4 deletions cli/workflows/cli_workflow_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@
from typing import Callable, Dict, Any
from mcp_agent.app import MCPApp

# Default truncation limit for CLI display
CLI_DISPLAY_TRUNCATE_LIMIT = 1000


def truncate_for_display(text: str, limit: int = CLI_DISPLAY_TRUNCATE_LIMIT) -> str:
"""
Truncate text for CLI display, adding ellipsis if truncated.

Args:
text: The text to truncate
limit: Maximum length before truncation

Returns:
Truncated text with '...' suffix if it exceeded the limit
"""
if len(text) > limit:
return text[:limit] + "..."
return text


class CLIWorkflowAdapter:
"""
Expand All @@ -20,6 +39,37 @@ class CLIWorkflowAdapter:
- Optimized error handling for CLI environments
- Streamlined interface for command-line usage
- Integration with the latest agent orchestration engine

Usage Examples:

File-based Input:
>>> adapter = CLIWorkflowAdapter(cli_interface=cli)
>>> await adapter.initialize_mcp_app()
>>> result = await adapter.process_input_with_orchestration(
... input_source="/path/to/file.py",
... input_type="file",
... enable_indexing=True
... )
>>> await adapter.cleanup_mcp_app()

Chat-based Input:
>>> adapter = CLIWorkflowAdapter(cli_interface=cli)
>>> await adapter.initialize_mcp_app()
>>> result = await adapter.process_input_with_orchestration(
... input_source="Implement a user authentication system",
... input_type="chat",
... enable_indexing=True
... )
>>> await adapter.cleanup_mcp_app()

Without CLI Interface (graceful fallback):
>>> adapter = CLIWorkflowAdapter() # No cli_interface provided
>>> await adapter.initialize_mcp_app()
>>> result = await adapter.execute_full_pipeline(
... input_source="/path/to/file.py",
... enable_indexing=True
... )
>>> await adapter.cleanup_mcp_app()
"""

def __init__(self, cli_interface=None):
Expand Down Expand Up @@ -308,11 +358,17 @@ async def process_input_with_orchestration(
input_source, enable_indexing=enable_indexing
)

# Truncate results at source to avoid passing large strings around
repo_result = pipeline_result.get("result", "")
return {
"status": pipeline_result["status"],
"analysis_result": "Integrated into agent orchestration pipeline",
"download_result": "Integrated into agent orchestration pipeline",
"repo_result": pipeline_result.get("result", ""),
"analysis_result": truncate_for_display(
"Integrated into agent orchestration pipeline"
),
"download_result": truncate_for_display(
"Integrated into agent orchestration pipeline"
),
"repo_result": truncate_for_display(repo_result),
"pipeline_mode": pipeline_result.get("pipeline_mode", "comprehensive"),
"error": pipeline_result.get("error"),
}
Expand All @@ -324,7 +380,7 @@ async def process_input_with_orchestration(

return {
"status": "error",
"error": error_msg,
"error": truncate_for_display(error_msg),
"analysis_result": "",
"download_result": "",
"repo_result": "",
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ aiofiles>=0.8.0
aiohttp>=3.8.0
anthropic
asyncio-mqtt
click>=8.0.0
docling
mcp-agent
mcp-server-git
Expand Down