Pass stdscr to _submit for realtime screen updates during processing

This commit is contained in:
Dita Aji Pratama 2026-05-12 16:28:07 +07:00
parent 293bd5d550
commit d4ec96ff62

View File

@ -228,7 +228,7 @@ class HendrikTUI:
def _handle_key(self, stdscr, key): def _handle_key(self, stdscr, key):
if key == 4: if key == 4:
self._submit() self._submit(stdscr)
elif key == 23: elif key == 23:
self._workspace_popup(stdscr) self._workspace_popup(stdscr)
elif key == 3: elif key == 3:
@ -308,7 +308,7 @@ class HendrikTUI:
"time": datetime.now().strftime("%H:%M"), "time": datetime.now().strftime("%H:%M"),
}) })
def _submit(self): def _submit(self, stdscr):
query = "\n".join(self.input_buffer).strip() query = "\n".join(self.input_buffer).strip()
if not query: if not query:
return return
@ -319,12 +319,16 @@ class HendrikTUI:
self.input_col = 0 self.input_col = 0
self.scroll = 999999 self.scroll = 999999
self.processing = True self.processing = True
self._draw(stdscr)
stdscr.refresh()
self.messages.append({"role": "user", "content": query}) self.messages.append({"role": "user", "content": query})
for step in range(self.agent_max_iterations): for step in range(self.agent_max_iterations):
self._log("system", f" step {step + 1} \u2014 LLM...") self._log("system", f" step {step + 1} \u2014 LLM...")
self.scroll = 999999 self.scroll = 999999
self._draw(stdscr)
stdscr.refresh()
response = self.llm.chat(self.messages, tools=self.TOOLS) response = self.llm.chat(self.messages, tools=self.TOOLS)
@ -340,13 +344,17 @@ class HendrikTUI:
if response.content and response.content.strip(): if response.content and response.content.strip():
self._log("ai", response.content) self._log("ai", response.content)
self.scroll = 999999 self.scroll = 999999
self._draw(stdscr)
stdscr.refresh()
for tc in response.tool_calls: for tc in response.tool_calls:
tname = tc["function"]["name"] tname = tc["function"]["name"]
targs = tc["function"]["arguments"]
self._log("system", f" \u2192 {tname}") self._log("system", f" \u2192 {tname}")
self.scroll = 999999 self.scroll = 999999
self._draw(stdscr)
stdscr.refresh()
self._execute_tool(tc) self._execute_tool(tc)
else: else:
if response.content:
self.messages.append({ self.messages.append({
"role": "assistant", "role": "assistant",
"content": response.content, "content": response.content,
@ -355,6 +363,8 @@ class HendrikTUI:
self._log("sep", "") self._log("sep", "")
self.processing = False self.processing = False
self.scroll = 999999 self.scroll = 999999
self._draw(stdscr)
stdscr.refresh()
return return
self._log("error", "Max iterations reached without final answer.") self._log("error", "Max iterations reached without final answer.")