Skip to content

Commit cfb4f2c

Browse files
committed
feat: Add "Reset" and "Quit" buttons to the TUI, enabling game resets and application termination.
1 parent c8d425e commit cfb4f2c

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

agents/attackers/interactive_tui/interactive_tui.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,13 @@ def compose(self) -> ComposeResult:
217217
yield Horizontal(
218218
Button("Take Action", variant="primary", id="act"),
219219
Button("Assist", variant="primary", id="assist"),
220-
Button("Assist & Play", variant="warning", id="play"),
220+
Button("Play", variant="warning", id="play"),
221+
Button("Hack the Future", variant="error", id="hack"),
222+
Vertical(classes="spacer"),
223+
Button("Reset", id="reset"),
224+
Button("Quit", id="quit"),
225+
classes="buttons-row"
221226
)
222-
yield Button("Hack the Future", variant="error", id="hack")
223227

224228
@on(Select.Changed)
225229
def select_changed(self, event: Select.Changed) -> None:
@@ -402,6 +406,22 @@ async def do_ask_llm():
402406
log.write(msg)
403407

404408
asyncio.create_task(do_ask_llm())
409+
elif event.button.id == "quit":
410+
if self.agent.socket:
411+
self.agent.terminate_connection()
412+
self.exit()
413+
elif event.button.id == "reset":
414+
log.write("Resetting the episode...")
415+
obs = self.agent.request_game_reset()
416+
if obs:
417+
self.current_obs = obs
418+
self._clear_state()
419+
tree_state = self.query_one(TreeState)
420+
tree = tree_state.children[0]
421+
self.update_tree(tree)
422+
log.write("Episode reset successfully.")
423+
else:
424+
log.write("[bold red]Reset failed![/bold red]")
405425
else:
406426
if self.model is not None:
407427
log.write(":hourglass: Waiting for the LLM...")

agents/attackers/interactive_tui/layout.tcss

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,33 @@ Screen {
3939

4040
#hack {
4141
margin: 0 1;
42+
}
43+
44+
#reset {
45+
background: darkcyan;
46+
color: white;
47+
}
48+
#reset:hover {
49+
background: cyan;
50+
color: black;
51+
}
52+
53+
#quit {
54+
background: indigo;
55+
color: white;
56+
}
57+
#quit:hover {
58+
background: purple;
59+
color: white;
60+
}
61+
62+
.spacer {
63+
width: 1fr;
64+
height: 1;
65+
}
66+
67+
.buttons-row {
68+
height: auto;
69+
width: 100%;
70+
column-span: 3;
4271
}

0 commit comments

Comments
 (0)