Skip to content

The agent that grows with you

fix(cli): after a busy-mode /steer the status bar keeps main's `~` estimate marker

Teknium82827b819a8b
diff --git a/hermes_cli/gateway_agent.py b/hermes_cli/gateway_agent.py
index 63b5369232a..6eeeb7518a4 100644
--- a/hermes_cli/gateway_agent.py
+++ b/hermes_cli/gateway_agent.py
@@ -130,6 +130,7 @@ class GatewayAgent:
self._turn_base_usage_anchor = None
self._context_tokens = 0
self._turn_calls_base = 0
+ self._turn_ask_index = None
self._usage_stale = False
self._current_task_id = self._current_turn_id = self._current_api_request_id = ""
self._memory_manager = None
@@ -394,6 +395,7 @@ class GatewayAgent:
def run_conversation(self, user_message, conversation_history=None, stream_callback=None,
task_id=None, persist_user_message=None, turn_author=None, **_kw):
history = list(conversation_history or [])
+ self._turn_ask_index = len(history) # the staged ask's row in this turn's transcript
self._turn_calls_base = self.session_api_calls
self._usage_stale = True
self._interrupt_requested = False
@@ -738,6 +740,13 @@ class GatewayAgent:
# that made calls this turn, never "no call".
calls = self.session_api_calls
base = last_user + 1 if calls > self._turn_calls_base or 0 < calls < self._turn_calls_base else last_user
+
+ # The turn's own ask, never a later user-role row of the same turn (a mid-turn /steer row).
+ ask = getattr(self, "_turn_ask_index", None)
+ last_user = ask if isinstance(ask, int) and 0 <= ask < len(messages) and messages[ask].get("role") == "user" \
+ else next((i for i in range(len(messages) - 1, -1, -1) if messages[i].get("role") == "user"),
+ len(messages) - 1)
+ base = last_user + 1 if self.session_api_calls > self._turn_calls_base else last_user
if base <= 0:
self._turn_base_usage_anchor = None
return
diff --git a/tests/hermes_cli/test_gateway_agent.py b/tests/hermes_cli/test_gateway_agent.py
index 733574f6732..b7aa62c671e 100644
--- a/tests/hermes_cli/test_gateway_agent.py
+++ b/tests/hermes_cli/test_gateway_agent.py
@@ -467,6 +467,19 @@ def test_turn_after_a_rewind_anchors_on_its_first_response(make_agent):
usage = dict(SESSION_USAGE, context_tokens=120, api_calls=1)
agent, client = make_agent([frame("message.complete", {"text": "done", "outcome": "completed"})],
result={"final_response": "done", "api_calls": 1})
+
+
+def test_a_mid_turn_steer_row_is_estimated_delta_like_main(make_agent):
+ """Main anchors the bar on the turn's first response priced over the history through the turn's
+ own ask; a /steer delivered mid-turn is a later user-role row, so it is delta and the bar shows `~`."""
+ usage = dict(SESSION_USAGE, context_tokens=900, api_calls=2)
+ suffix = [{"role": "assistant", "content": "", "tool_calls": [{"id": "c1", "type": "function",
+ "function": {"name": "terminal", "arguments": "{}"}}]},
+ {"role": "tool", "tool_call_id": "c1", "content": "ok"},
+ {"role": "user", "content": "[USER STEER] also this", "display_kind": "steer"},
+ {"role": "assistant", "content": "done"}]
+ agent, client = make_agent([frame("message.complete", {"text": "done", "outcome": "completed"})],
+ result={"final_response": "done", "api_calls": 2, "messages": suffix})
original = client.rpc
async def rpc(method, *, _timeout=None, **params):
@@ -479,3 +492,8 @@ def test_turn_after_a_rewind_anchors_on_its_first_response(make_agent):
{"role": "assistant", "content": "b"}])
msgs = agent._session_messages
assert agent._turn_base_usage_anchor["base_count"] == len(msgs) - 1 # through the ask; reply follows
+
+
+ agent.run_conversation("slow", conversation_history=[{"role": "user", "content": "a"},
+ {"role": "assistant", "content": "b"}])
+ assert agent._turn_base_usage_anchor["base_count"] == 3 # history + the ask, not the steer row