Python · 3162 bytes Raw Blame History
1 """Formatting helpers for user-visible runtime status."""
2
3 from __future__ import annotations
4
5 from ..runtime.owner_metadata import normalize_runtime_owner_path
6
7
8 def format_definition_of_done_parts(
9 status: str,
10 pending_items_count: int,
11 last_verification_result: str,
12 verification_attempt: str = "",
13 ) -> list[str]:
14 """Format definition-of-done state for the status line."""
15 if not status:
16 return []
17
18 dod_color = {
19 "draft": "cyan",
20 "in_progress": "cyan",
21 "verifying": "yellow",
22 "fixing": "magenta",
23 "done": "green",
24 "failed": "red",
25 }.get(status, "white")
26 parts = [f"[{dod_color}]DoD: {status}[/{dod_color}]"]
27 parts.append(f"[dim]{pending_items_count} pending[/dim]")
28
29 if last_verification_result:
30 verify_color = "green" if last_verification_result == "passed" else "red"
31 if last_verification_result == "skipped":
32 verify_color = "dim"
33 verify_label = f"verify {last_verification_result}"
34 if verification_attempt:
35 verify_label = f"{verify_label} ({verification_attempt})"
36 parts.append(
37 f"[{verify_color}]{verify_label}[/{verify_color}]"
38 )
39
40 return parts
41
42
43 def format_permission_mode_part(mode: str) -> str | None:
44 """Format the active permission mode for the status line."""
45 if not mode:
46 return None
47
48 color = {
49 "read-only": "green",
50 "workspace-write": "yellow",
51 "danger-full-access": "red",
52 "prompt": "magenta",
53 "allow": "cyan",
54 }.get(mode, "white")
55 return f"[{color}]perm {mode}[/{color}]"
56
57
58 def format_capability_part(capability: str) -> str | None:
59 """Format the active capability profile for the status line."""
60
61 if not capability:
62 return None
63 return f"[dim]cap {capability}[/dim]"
64
65
66 def format_session_part(session_id: str) -> str | None:
67 """Format the active session id for the status line."""
68
69 if not session_id:
70 return None
71 return f"[dim]session {session_id[-8:]}[/dim]"
72
73
74 def format_runtime_owner_part(owner_path: str) -> str | None:
75 """Format the active runtime-owner path for the status line."""
76
77 normalized_path = normalize_runtime_owner_path(owner_path)
78 if not normalized_path:
79 return None
80 return f"[dim]owner {normalized_path}[/dim]"
81
82
83 def format_workflow_mode_part(mode: str) -> str | None:
84 """Format the active workflow mode for the status line."""
85
86 if not mode:
87 return None
88
89 color = {
90 "clarify": "magenta",
91 "plan": "cyan",
92 "execute": "blue",
93 "verify": "green",
94 }.get(mode, "white")
95 return f"[{color}]flow {mode}[/{color}]"
96
97
98 def format_turn_phase_part(phase: str) -> str | None:
99 """Format the active turn phase for the status line."""
100
101 if not phase:
102 return None
103
104 color = {
105 "prepare": "cyan",
106 "assistant": "blue",
107 "repair": "magenta",
108 "tools": "yellow",
109 "critique": "cyan",
110 "completion": "green",
111 "finalize": "white",
112 }.get(phase, "white")
113 return f"[{color}]phase {phase}[/{color}]"