Skip to content

Commit 0cc2878

Browse files
authored
Merge pull request #96 from michaelos443/fix/ctrl-c-duplicate-messages
Fix duplicate messages when pressing Ctrl-C twice
2 parents 9f95229 + 22aed96 commit 0cc2878

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

cli/workflows/cli_workflow_adapter.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@
2222
import httpx
2323
from mcp_agent.app import MCPApp
2424

25+
# Default truncation limit for CLI display
26+
CLI_DISPLAY_TRUNCATE_LIMIT = 1000
27+
28+
29+
def truncate_for_display(text: str, limit: int = CLI_DISPLAY_TRUNCATE_LIMIT) -> str:
30+
"""
31+
Truncate text for CLI display, adding ellipsis if truncated.
32+
33+
Args:
34+
text: The text to truncate
35+
limit: Maximum length before truncation
36+
37+
Returns:
38+
Truncated text with '...' suffix if it exceeded the limit
39+
"""
40+
if len(text) > limit:
41+
return text[:limit] + "..."
42+
return text
43+
2544

2645
class CLIWorkflowAdapter:
2746
"""
@@ -32,6 +51,37 @@ class CLIWorkflowAdapter:
3251
- Optimized error handling for CLI environments
3352
- Streamlined interface for command-line usage
3453
- Integration with the latest agent orchestration engine
54+
55+
Usage Examples:
56+
57+
File-based Input:
58+
>>> adapter = CLIWorkflowAdapter(cli_interface=cli)
59+
>>> await adapter.initialize_mcp_app()
60+
>>> result = await adapter.process_input_with_orchestration(
61+
... input_source="/path/to/file.py",
62+
... input_type="file",
63+
... enable_indexing=True
64+
... )
65+
>>> await adapter.cleanup_mcp_app()
66+
67+
Chat-based Input:
68+
>>> adapter = CLIWorkflowAdapter(cli_interface=cli)
69+
>>> await adapter.initialize_mcp_app()
70+
>>> result = await adapter.process_input_with_orchestration(
71+
... input_source="Implement a user authentication system",
72+
... input_type="chat",
73+
... enable_indexing=True
74+
... )
75+
>>> await adapter.cleanup_mcp_app()
76+
77+
Without CLI Interface (graceful fallback):
78+
>>> adapter = CLIWorkflowAdapter() # No cli_interface provided
79+
>>> await adapter.initialize_mcp_app()
80+
>>> result = await adapter.execute_full_pipeline(
81+
... input_source="/path/to/file.py",
82+
... enable_indexing=True
83+
... )
84+
>>> await adapter.cleanup_mcp_app()
3585
"""
3686

3787
# Maximum length for result strings to avoid building giant strings
@@ -430,7 +480,7 @@ async def process_input_with_orchestration(
430480

431481
return {
432482
"status": "error",
433-
"error": error_msg,
483+
"error": truncate_for_display(error_msg),
434484
"analysis_result": "",
435485
"download_result": "",
436486
"repo_result": "",

0 commit comments

Comments
 (0)