diff --git a/cli/workflows/cli_workflow_adapter.py b/cli/workflows/cli_workflow_adapter.py index b917950d..42cff691 100644 --- a/cli/workflows/cli_workflow_adapter.py +++ b/cli/workflows/cli_workflow_adapter.py @@ -22,6 +22,25 @@ import httpx 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: """ @@ -32,6 +51,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() """ # Maximum length for result strings to avoid building giant strings @@ -430,7 +480,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": "",