From 00a7449293ce37029b70103e592ac970bdd4c9e5 Mon Sep 17 00:00:00 2001 From: giveen Date: Tue, 20 Jan 2026 12:31:48 -0700 Subject: [PATCH] fix(tui): ensure workspace restores supersede manual target messages --- pentestagent/interface/tui.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/pentestagent/interface/tui.py b/pentestagent/interface/tui.py index 29d65f7..df4b970 100644 --- a/pentestagent/interface/tui.py +++ b/pentestagent/interface/tui.py @@ -1678,6 +1678,12 @@ class PentestAgentTUI(App): self.agent.conversation_history.append( AgentMessage(role="system", content=f"Operator set target to {target}") ) + # Track manual target override so workspace restores can remove + # or supersede this message when appropriate. + try: + setattr(self.agent, "_manual_target", target) + except Exception: + pass except Exception as e: logging.getLogger(__name__).exception( "Failed to append target change to agent history: %s", e @@ -2020,6 +2026,28 @@ Be concise. Use the actual data from notes.""" self.target = last if self.agent: self.agent.target = last + # If the operator set a manual target while no + # workspace was active, remove/supersede that + # system message so the LLM uses the workspace + # target instead of the stale manual one. + try: + manual = getattr(self.agent, "_manual_target", None) + if manual: + self.agent.conversation_history = [ + m + for m in self.agent.conversation_history + if not ( + m.role == "system" + and isinstance(m.content, str) + and m.content.strip().startswith("Operator set target to") + ) + ] + try: + delattr(self.agent, "_manual_target") + except Exception: + pass + except Exception: + pass try: from pentestagent.agents.base_agent import AgentMessage