Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Memory: an entry the person edits becomes theirs (Rigel M1)

Lin (kwant bot)ed04587753fe
diff --git a/src/db/continuity.rs b/src/db/continuity.rs
index e8aa88f8..426a8a66 100644
--- a/src/db/continuity.rs
+++ b/src/db/continuity.rs
@@ -404,7 +404,8 @@ impl Database {
})
}
- /// Only the kwant's own memory can be changed.
+ /// The person editing a memory. Only the kwant's own memory can be changed, and the edited
+ /// entry becomes the person's (`source = 'user'`), so the bot can no longer change or remove it.
pub async fn update_memory(
&self,
kwant_id: &str,
@@ -413,7 +414,7 @@ impl Database {
) -> Result<Memory, MemoryError> {
let text = clean_memory_text(text)?;
let res = sqlx::query(
- "UPDATE kwant_memories SET text = ?, updated_at = ? WHERE id = ? AND kwant_id = ?",
+ "UPDATE kwant_memories SET text = ?, source = 'user', updated_at = ? WHERE id = ? AND kwant_id = ?",
)
.bind(&text)
.bind(Utc::now())
diff --git a/tests/continuity_test.rs b/tests/continuity_test.rs
index 23c4b05b..703c612c 100644
--- a/tests/continuity_test.rs
+++ b/tests/continuity_test.rs
@@ -859,6 +859,28 @@ async fn self_tools_are_scoped_to_the_turn_and_kwant() {
// The person's own edit and delete still work
assert_eq!(db.update_memory(&k1.id, &mine.id, "Never email clients on weekends").await.unwrap().text, "Never email clients on weekends");
assert!(db.delete_memory(&k1.id, &mine.id).await.unwrap());
+ // Rigel's M1: once the person edits the bot's own note, it is theirs and the bot can't undo it
+ let edited = db.add_memory(&k1.id, "Oleks likes Tuesday calls", "agent").await.unwrap();
+ let (status, body) = req(
+ &app,
+ "PATCH",
+ &format!("/api/kwants/{}/memories/{}", k1.id, edited.id),
+ Some(json!({"text": "Oleks never takes calls on Tuesday"})),
+ )
+ .await;
+ assert_eq!(status, StatusCode::OK, "{body}");
+ assert_eq!(body["source"], "user", "{body}");
+ for (name, args) in [
+ ("memory_update", json!({"id": edited.id, "text": "Oleks likes Tuesday calls"})),
+ ("memory_remove", json!({"id": edited.id})),
+ ] {
+ let (_, res) = call(&app, "POST", "/api/mcp/self", Some(tool(name, args)), &[("authorization", &auth)]).await;
+ assert_eq!(res["result"]["isError"], true, "{name}: {res}");
+ assert!(text(&res).contains("the person wrote this memory"), "{name}: {res}");
+ }
+ let kept = db.list_memories(&k1.id).await.unwrap();
+ assert!(kept.iter().any(|m| m.id == edited.id && m.source == "user" && m.text == "Oleks never takes calls on Tuesday"));
+ assert!(db.delete_memory(&k1.id, &edited.id).await.unwrap());
// Search sees k1's direct chat, not k2's, nor a channel k1 isn't in
let (_, res) = call(