File size: 4,695 Bytes
1297e91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
706d95d
1297e91
 
706d95d
 
 
 
1297e91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
706d95d
 
 
1297e91
 
706d95d
1297e91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9689843
1297e91
 
 
 
9689843
 
 
1297e91
9689843
 
 
1297e91
 
 
 
706d95d
1297e91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
706d95d
 
 
1297e91
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
"""
Terminal display utilities with colors and formatting
"""


# ANSI color codes
class Colors:
    RED = "\033[91m"
    GREEN = "\033[92m"
    YELLOW = "\033[93m"
    BLUE = "\033[94m"
    MAGENTA = "\033[95m"
    CYAN = "\033[96m"
    BOLD = "\033[1m"
    UNDERLINE = "\033[4m"
    RESET = "\033[0m"


def truncate_to_lines(text: str, max_lines: int = 6) -> str:
    """Truncate text to max_lines, adding '...' if truncated"""
    lines = text.split("\n")
    if len(lines) <= max_lines:
        return text
    return (
        "\n".join(lines[:max_lines])
        + f"\n{Colors.CYAN}... ({len(lines) - max_lines} more lines){Colors.RESET}"
    )


def format_header(text: str, emoji: str = "") -> str:
    """Format a header with bold"""
    full_text = f"{emoji} {text}" if emoji else text
    return f"{Colors.BOLD}{full_text}{Colors.RESET}"


def format_plan_display() -> str:
    """Format the current plan for display (no colors, full visibility)"""
    from agent.tools.plan_tool import get_current_plan

    plan = get_current_plan()
    if not plan:
        return ""

    lines = ["\n" + "=" * 60]
    lines.append("CURRENT PLAN")
    lines.append("=" * 60 + "\n")

    # Group by status
    completed = [t for t in plan if t["status"] == "completed"]
    in_progress = [t for t in plan if t["status"] == "in_progress"]
    pending = [t for t in plan if t["status"] == "pending"]

    if completed:
        lines.append("Completed:")
        for todo in completed:
            lines.append(f"  [x] {todo['id']}. {todo['content']}")
        lines.append("")

    if in_progress:
        lines.append("In Progress:")
        for todo in in_progress:
            lines.append(f"  [~] {todo['id']}. {todo['content']}")
        lines.append("")

    if pending:
        lines.append("Pending:")
        for todo in pending:
            lines.append(f"  [ ] {todo['id']}. {todo['content']}")
        lines.append("")

    lines.append(
        f"Total: {len(plan)} todos ({len(completed)} completed, {len(in_progress)} in progress, {len(pending)} pending)"
    )
    lines.append("=" * 60 + "\n")

    return "\n".join(lines)


def format_error(message: str) -> str:
    """Format an error message in red"""
    return f"{Colors.RED}ERROR: {message}{Colors.RESET}"


def format_success(message: str, emoji: str = "") -> str:
    """Format a success message in green"""
    prefix = f"{emoji} " if emoji else ""
    return f"{Colors.GREEN}{prefix}{message}{Colors.RESET}"


def format_tool_call(tool_name: str, arguments: str) -> str:
    """Format a tool call message"""
    return f"{Colors.YELLOW}Calling tool: {Colors.BOLD}{tool_name}{Colors.RESET}{Colors.YELLOW} with arguments: {arguments}{Colors.RESET}"


def format_tool_output(output: str, success: bool, truncate: bool = True) -> str:
    """Format tool output with color and optional truncation"""
    original_length = len(output)
    if truncate:
        output = truncate_to_lines(output, max_lines=6)

    if success:
        return (
            f"{Colors.YELLOW}Tool output ({original_length} tkns): {Colors.RESET}\n{output}"
        )
    else:
        return (
            f"{Colors.RED}Tool output ({original_length} tokens): {Colors.RESET}\n{output}"
        )


def format_turn_complete() -> str:
    """Format turn complete message in green with hugging face emoji"""
    return f"{Colors.GREEN}{Colors.BOLD}\U0001f917 Turn complete{Colors.RESET}\n"


def format_separator(char: str = "=", length: int = 60) -> str:
    """Format a separator line"""
    return char * length


def format_plan_tool_output(todos: list) -> str:
    """Format the plan tool output (no colors, full visibility)"""
    if not todos:
        return "Plan is empty."

    lines = ["Plan updated successfully", ""]

    # Group by status
    completed = [t for t in todos if t["status"] == "completed"]
    in_progress = [t for t in todos if t["status"] == "in_progress"]
    pending = [t for t in todos if t["status"] == "pending"]

    if completed:
        lines.append("Completed:")
        for todo in completed:
            lines.append(f"  [x] {todo['id']}. {todo['content']}")
        lines.append("")

    if in_progress:
        lines.append("In Progress:")
        for todo in in_progress:
            lines.append(f"  [~] {todo['id']}. {todo['content']}")
        lines.append("")

    if pending:
        lines.append("Pending:")
        for todo in pending:
            lines.append(f"  [ ] {todo['id']}. {todo['content']}")
        lines.append("")

    lines.append(
        f"Total: {len(todos)} todos ({len(completed)} completed, {len(in_progress)} in progress, {len(pending)} pending)"
    )

    return "\n".join(lines)