Skip to content
Merged
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
52 changes: 51 additions & 1 deletion cli/workflows/cli_workflow_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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
Expand Down Expand Up @@ -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": "",
Expand Down
Loading