-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_layout.py
More file actions
199 lines (159 loc) · 5.78 KB
/
cli_layout.py
File metadata and controls
199 lines (159 loc) · 5.78 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
"""Rich landing page, banner, and help renderer for the Self-Escalate CLI."""
from __future__ import annotations
import os
from collections.abc import Sequence
import click
from rich.box import ROUNDED
from rich.console import Console
from rich.console import Group as RichGroup_
from rich.panel import Panel
from rich.rule import Rule
from rich.table import Table
from rich.text import Text
def _get_version() -> str:
try:
from importlib.metadata import version
return version("self-escalate-agent")
except Exception: # noqa: BLE001
return "0.1.0"
def _get_model() -> str:
return os.getenv("ANTHROPIC_MODEL", "claude-sonnet-4-6")
# Pixel-art staircase — represents escalation (each step = retry level).
_STAIR = (
" ██",
" ████",
" ██████",
" ████████",
"██████████",
)
_HELP_COMMANDS: tuple[tuple[str, str], ...] = (
("chat", "Start an interactive self-escalating task session."),
("plugin list", "List installed domain plugins."),
("plugin install", "Install a domain plugin from a local directory."),
("config set", "Print env-var export for a config key."),
)
_LANDING_COMMANDS: tuple[tuple[str, str], ...] = (
("self-escalate chat", "Start a task session"),
("self-escalate chat --domain <name>", "Start with a domain plugin"),
("self-escalate chat --max-retry 5", "Increase retry limit before escalation"),
("self-escalate chat --persist", "Save session JSON after completion"),
("self-escalate plugin list", "List installed domain plugins"),
("self-escalate plugin install <path>", "Install a domain plugin"),
)
_SHORT_OPTIONS: tuple[tuple[str, str], ...] = (
("--version", "Show the version and exit."),
("-h, --help", "Show this message and exit."),
)
_CHAT_HINTS = (
("Type a task", "to start an investigation"),
("intent_mismatch", "triggers a retry (up to --max-retry)"),
("satisfied feedback", "resolves the session"),
("escalation", "opens a GitHub issue automatically"),
)
def _render_rows(
console: Console,
*,
title: str,
rows: Sequence[tuple[str, str]],
width: int,
) -> None:
console.print(Text.assemble((f" {title}:", "bold white")))
for label, description in rows:
console.print(
Text.assemble((" ", ""), (f"{label:<{width}}", "bold cyan"), description)
)
def render_help() -> None:
"""Render the root help view."""
console = Console(highlight=False)
console.print()
console.print(
Text.assemble(
(" Usage: "),
("self-escalate", "bold white"),
(" [OPTIONS] COMMAND [ARGS]..."),
)
)
console.print()
_render_rows(console, title="Commands", rows=_HELP_COMMANDS, width=16)
console.print()
_render_rows(console, title="Options", rows=_SHORT_OPTIONS, width=16)
console.print()
def _left_panel_content(*, subtitle: str | None = None) -> RichGroup_:
"""Left column: staircase art + model + cwd."""
stair = Text("\n".join(_STAIR), style="bold bright_cyan", justify="center")
info = Text(_get_model(), justify="center", style="dim")
parts: list = [Text(""), stair, Text("")]
if subtitle:
sub = Text(subtitle, justify="center", style="dim")
parts.append(sub)
parts.append(info)
parts.append(Text(""))
return RichGroup_(*parts)
def _right_panel_content(rows: Sequence[tuple[str, str]], *, title: str) -> RichGroup_:
"""Right column: a titled list of hints."""
header = Text(title, style="bold white")
sep = Rule(style="dim")
lines: list = [header, sep]
for label, desc in rows:
line = Text()
line.append(label, style="bold cyan")
line.append(" ", style="")
line.append(desc, style="dim")
lines.append(line)
lines.append(Text(""))
return RichGroup_(*lines)
def render_banner(console: Console | None = None) -> None:
"""Print the chat session identity banner (Claude Code style)."""
c = console or Console(highlight=False)
ver = _get_version()
left = _left_panel_content()
right = _right_panel_content(_CHAT_HINTS, title="How it works")
# Two-column grid separated by a │ rule
grid = Table.grid(padding=(0, 2), expand=True)
grid.add_column(ratio=2, justify="center")
grid.add_column(width=1)
grid.add_column(ratio=3)
grid.add_row(left, Text("│", style="dim"), right)
c.print()
c.print(
Panel(
grid,
title=f"[dim]─── self-escalate v{ver}[/dim]",
title_align="left",
box=ROUNDED,
border_style="dim",
padding=(0, 1),
expand=True,
)
)
c.print()
def render_landing() -> None:
"""Render the landing page shown when no subcommand is given."""
c = Console(highlight=False)
ver = _get_version()
left = _left_panel_content(subtitle="retries · reflects · escalates")
right = _right_panel_content(_LANDING_COMMANDS, title="Quick start")
grid = Table.grid(padding=(0, 2), expand=True)
grid.add_column(ratio=2, justify="center")
grid.add_column(width=1)
grid.add_column(ratio=3)
grid.add_row(left, Text("│", style="dim"), right)
c.print()
c.print(
Panel(
grid,
title=f"[dim]─── self-escalate v{ver}[/dim]",
title_align="left",
box=ROUNDED,
border_style="dim",
padding=(0, 1),
expand=True,
)
)
c.print()
_render_rows(c, title="Options", rows=_SHORT_OPTIONS, width=16)
c.print()
class RichGroup(click.Group):
"""Click group with a Rich-powered help screen."""
def format_help(self, _ctx: click.Context, _formatter: click.HelpFormatter) -> None:
render_help()