Skip to content

Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.

fix(tui): keep the memory screen on the entry you picked

leepokai71f50d0cde17
diff --git a/host/src/tui/manage/fields.rs b/host/src/tui/manage/fields.rs
index 6ec4f712..6ff97eb6 100644
--- a/host/src/tui/manage/fields.rs
+++ b/host/src/tui/manage/fields.rs
@@ -80,8 +80,9 @@ impl App {
}
Submit::MemoryFile { bot, shared, name, base } => {
let file = name.clone().map_or_else(|| values.get("file").cloned().unwrap_or_default(), Value::from);
- let body =
- json!({"botId": bot, "file": file, "shared": shared, "content": values["content"], "base": base});
+ // A note keeps its text as typed: trimming would drop its last line break.
+ let content = f.inputs.iter().find(|i| i.name == "content").map_or("", |i| i.ed.text.as_str());
+ let body = json!({"botId": bot, "file": file, "shared": shared, "content": content, "base": base});
self.sheet("saveMemoryFile", body, Reply::FieldsSaved);
}
}
diff --git a/host/src/tui/manage/memory.rs b/host/src/tui/manage/memory.rs
index ac68faee..59308245 100644
--- a/host/src/tui/manage/memory.rs
+++ b/host/src/tui/manage/memory.rs
@@ -111,6 +111,17 @@ impl MemorySheet {
list.as_array().cloned().unwrap_or_default()
}
+ /// Takes a fresh `memory` reply, keeping the cursor on the row it was on: pinning or archiving reorders them.
+ pub fn show(&mut self, view: Value) {
+ let key = |row: &Value| json!([row["id"], row["name"], row["shared"]]);
+ let was = self.rows().get(self.cursor).map(key);
+ self.view = Some(view);
+ let rows = self.rows();
+ self.cursor = was
+ .and_then(|k| rows.iter().position(|row| key(row) == k))
+ .unwrap_or_else(|| self.cursor.min(rows.len().saturating_sub(1)));
+ }
+
/// Sections worth showing: project memory only when the folder has one.
pub fn sections(&self) -> Vec<Section> {
let project = self.view.as_ref().is_some_and(|v| v["projectMemory"].is_object());
@@ -348,3 +359,26 @@ impl App {
/// What a new note starts with.
const NOTE_TEMPLATE: &str = "---\ndescription: When to read this note\n---\n";
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn the_cursor_follows_its_entry_when_pinning_reorders_them() {
+ let view = |ids: [i64; 3]| json!({"bot": {"entries": ids.map(|id| json!({"id": id}))}});
+ let mut m = MemorySheet {
+ bot: "b".into(),
+ view: Some(view([1, 2, 3])),
+ section: Section::Bot,
+ cursor: 2,
+ mode: MemoryMode::Browse,
+ error: None,
+ busy: false,
+ };
+ m.show(view([3, 1, 2]));
+ assert_eq!(m.cursor, 0, "entry 3 was pinned to the top");
+ m.show(view([1, 2, 4]));
+ assert_eq!(m.cursor, 0, "gone: the cursor stays in range");
+ }
+}
diff --git a/host/src/tui/manage/replies.rs b/host/src/tui/manage/replies.rs
index d6a0755f..d864f0e9 100644
--- a/host/src/tui/manage/replies.rs
+++ b/host/src/tui/manage/replies.rs
@@ -20,8 +20,7 @@ impl App {
if let Overlay::Memory(m) = o
&& m.bot == bot
{
- m.view = Some(v.clone());
- m.cursor = m.cursor.min(m.rows().len().saturating_sub(1));
+ m.show(v.clone());
m.busy = false;
m.error = None;
}
diff --git a/host/src/tui/sheets/memory_view.rs b/host/src/tui/sheets/memory_view.rs
index b43b9bc5..8749c6a2 100644
--- a/host/src/tui/sheets/memory_view.rs
+++ b/host/src/tui/sheets/memory_view.rs
@@ -4,6 +4,7 @@ use super::{
App, Buffer, Rect, centered, footer, frame_box, input_line, name_of, page_tabs, put, row, s, theme, u, window,
};
use crate::tui::manage::{MemoryMode, MemorySheet, Page, Section};
+use crate::tui::md::truncate;
use crate::tui::view::when;
use ratatui::widgets::{Paragraph, Widget, Wrap};
use serde_json::Value;
@@ -204,7 +205,14 @@ fn note(buf: &mut Buffer, body: Rect, app: &App, memory: &MemorySheet, detail: O
put(buf, body.x, body.y, body.width, "Loading…", palette.dim.patch(palette.panel));
return;
};
- put(buf, body.x, body.y, body.width, s(detail, "path"), palette.dim.patch(palette.panel));
+ put(
+ buf,
+ body.x,
+ body.y,
+ body.width,
+ &truncate(s(detail, "path"), usize::from(body.width)),
+ palette.dim.patch(palette.panel),
+ );
let versions = detail["versions"].as_array().cloned().unwrap_or_default();
let listed = u(versions.len().min(6));
let text = Rect::new(body.x, body.y + 2, body.width, body.height.saturating_sub(4 + listed));
@@ -235,7 +243,14 @@ fn note(buf: &mut Buffer, body: Rect, app: &App, memory: &MemorySheet, detail: O
fn project(buf: &mut Buffer, body: Rect, memory: &MemorySheet) {
let palette = theme();
let Some(project) = memory.view.as_ref().map(|v| &v["projectMemory"]) else { return };
- put(buf, body.x, body.y, body.width, s(project, "path"), palette.dim.patch(palette.panel));
+ put(
+ buf,
+ body.x,
+ body.y,
+ body.width,
+ &truncate(s(project, "path"), usize::from(body.width)),
+ palette.dim.patch(palette.panel),
+ );
let text = Rect::new(body.x, body.y + 2, body.width, body.height.saturating_sub(2));
Paragraph::new(s(project, "text"))
.wrap(Wrap { trim: false })