@@ -223,6 +223,7 @@ struct TuiState {
223223 float tokens_per_sec = 0 .0f ;
224224 int kv_used = 0 ;
225225 int kv_total = 1 ;
226+ int kv_percent = 0 ;
226227 size_t vram_used = 0 ;
227228 size_t vram_total = 1 ;
228229 int term_rows = 0 ;
@@ -236,6 +237,8 @@ struct TuiState {
236237 void tick_spinner ();
237238 // Toggle thinking mode; redraws header immediately.
238239 void set_thinking (bool on);
240+ void update_usage (int tokens_sec, const LlamaMemoryInfo &mem);
241+
239242 // ── lifecycle ─────────────────────────────────────────────────────
240243 void init ();
241244 void destroy ();
@@ -1360,6 +1363,15 @@ void TuiState::set_thinking(bool on) {
13601363 notcurses_render (nc);
13611364}
13621365
1366+ void TuiState::update_usage (int tokens_sec, const LlamaMemoryInfo &mem) {
1367+ tokens_per_sec = tokens_sec;
1368+ kv_used = mem.kv_used ;
1369+ kv_total = mem.kv_total ;
1370+ kv_percent = mem.kv_percent ;
1371+ vram_used = mem.vram_used ;
1372+ vram_total = mem.vram_total ;
1373+ }
1374+
13631375//
13641376// TuiState content helpers
13651377//
@@ -2033,22 +2045,31 @@ std::string AgentState::process_tool(const std::string &cmd, const NitroConfig &
20332045 const std::vector<std::string> &run_allowed = cfg.run_allowed ;
20342046
20352047 std::string op, arg1, arg2;
2036- auto sp1 = cmd.find_first_of (" \n " );
2037- if (sp1 == std::string::npos) {
2048+ auto WS = cmd.find_first_of (" \n " );
2049+ if (WS == std::string::npos) {
20382050 op = trim (cmd);
20392051 } else {
2040- op = trim (cmd.substr (0 , sp1));
2041- std::string rest = cmd.substr (sp1 + 1 );
2052+ op = trim (cmd.substr (0 , WS ));
2053+ std::string rest = cmd.substr (WS + 1 );
2054+ // clear leading WS from rest
20422055 rest.erase (0 , rest.find_first_not_of (" \t " ));
2043- auto sp2 = rest.find (' ' );
2044- if (sp2 == std::string::npos) {
2045- sp2 = rest.find (' \n ' );
2056+
2057+ // handle space of newline separator
2058+ // TOOL:WRITE src/render_transport.cpp\n#include "render_transport.h"\n...
2059+ // TOOL:WRITE src/render_transport.cpp #include "render_transport.h"\n ...
2060+ auto NL = rest.find (' \n ' );
2061+ auto SP = rest.find (' ' );
2062+ int sep;
2063+ if (NL != std::string::npos && (SP == std::string::npos || NL < SP )) {
2064+ sep = NL ;
2065+ } else {
2066+ sep = SP ;
20462067 }
2047- if (sp2 == std::string::npos) {
2068+ if (sep == std::string::npos) {
20482069 arg1 = rest;
20492070 } else {
2050- arg1 = rest.substr (0 , sp2 );
2051- arg2 = rest.substr (sp2 + 1 );
2071+ arg1 = rest.substr (0 , sep );
2072+ arg2 = rest.substr (sep + 1 );
20522073 }
20532074 }
20542075
@@ -2243,13 +2264,16 @@ bool AgentState::run_turn(const std::string &user_message, const NitroConfig &cf
22432264 }
22442265 tui.append_line (ICON_ERR + content);
22452266 }
2246- tui.tokens_per_sec = tokens_per_sec ( );
2267+ tui.update_usage ( tokens_per_sec (), llama-> memory_info () );
22472268 if (!llama->add_message (*iter, " tool_result" , content)) {
22482269 tui.append_line (ICON_ERR + " tool result inject: " + llama->last_error ());
22492270 }
22502271 if (!iter->_has_next ) {
22512272 tui.append_line (ICON_ERR + " failed to evoke tool response: " + llama->last_error ());
22522273 }
2274+ if (llama->is_memory_flush ()) {
2275+ tui.append_line (ICON_ERR + " Warning! - memory has been flushed!" );
2276+ }
22532277 tui.redraw_all ();
22542278 };
22552279
@@ -2375,18 +2399,14 @@ bool AgentState::run_turn(const std::string &user_message, const NitroConfig &cf
23752399
23762400 tui.flush_token_acc ();
23772401 tui.set_thinking (false );
2378- tui.tokens_per_sec = tokens_per_sec ();
2379- LlamaMemoryInfo mem = llama->memory_info ();
2380- tui.kv_used = mem.kv_used ;
2381- tui.kv_total = mem.kv_total ;
2382- tui.vram_used = mem.vram_used ;
2383- tui.vram_total = mem.vram_total ;
2402+ tui.update_usage (tokens_per_sec (), llama->memory_info ());
2403+
23842404 char stat[128 ];
23852405 auto patterm = ICON_SYS + " %.1f tok/s (%d tokens) KV %.1f%%" ;
23862406 std::snprintf (stat, sizeof (stat), patterm.c_str (),
23872407 (double )tui.tokens_per_sec ,
23882408 iter->_tokens_generated ,
2389- (double )mem .kv_percent );
2409+ (double )tui .kv_percent );
23902410 tui.append_line (stat);
23912411 tui.redraw_all ();
23922412 return true ;
@@ -2710,8 +2730,12 @@ int main(int argc, char **argv) {
27102730 AgentState agent;
27112731 if (!cfg.model_path .empty ()) {
27122732 if (agent.setup_model (cfg, tui)) {
2733+ tui.append_line (ICON_SYS + " Loading context..." );
2734+ tui.redraw_all ();
27132735 std::string sysp = build_system_prompt (cfg);
27142736 agent.reset_conversation (sysp, tui);
2737+ tui.append_line (ICON_SYS + " Ready" );
2738+ tui.redraw_all ();
27152739 }
27162740 if (!cfg.embed_path .empty ()) {
27172741 agent.setup_embed (cfg.embed_path , tui);
0 commit comments