diff --git a/cli/cli_app.py b/cli/cli_app.py index 0b0627fa..9bc93a52 100644 --- a/cli/cli_app.py +++ b/cli/cli_app.py @@ -255,7 +255,8 @@ async def run_interactive_session(self): self.cli.print_status("Session ended by user", "info") except KeyboardInterrupt: - print(f"\n{Colors.WARNING}⚠️ Process interrupted by user{Colors.ENDC}") + # Re-raise to let main() handle it uniformly + raise except Exception as e: print(f"\n{Colors.FAIL}❌ Unexpected error: {str(e)}{Colors.ENDC}") finally: diff --git a/cli/workflows/cli_workflow_adapter.py b/cli/workflows/cli_workflow_adapter.py index dda79b3d..ad787078 100644 --- a/cli/workflows/cli_workflow_adapter.py +++ b/cli/workflows/cli_workflow_adapter.py @@ -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: """ @@ -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): @@ -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"), } @@ -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": "", diff --git a/requirements.txt b/requirements.txt index d185cd68..5cad500e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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