Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(web): show the first version's date as Created
Peterson Salmedf937f1fc7c1
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6bf29b1a..b61078a6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0hand-written forms differently: a numeric-looking `title` or tag such as`007` is no longer used, a `!!timestamp`-tagged title fails that page'simport, and a custom-tagged title (`!foo x`) imports as its plain text.+- Fixed the web page header showing the date of the latest version as+ "Created", so a page rewritten many times looked new. It now shows when the+ first version was written. "Updated" is unchanged. (#NNNN)## [2.6.5] - 2026-10-12diff --git a/Cargo.lock b/Cargo.lockindex d430a143..bacdb3f3 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -282,6 +282,7 @@ dependencies = ["base64 0.22.1","jiff","pulldown-cmark",+ "rusqlite","serde","serde_json","sha2",diff --git a/crates/ai-memory-store/src/reader.rs b/crates/ai-memory-store/src/reader.rsindex 2cec517e..c2a056e8 100644--- a/crates/ai-memory-store/src/reader.rs+++ b/crates/ai-memory-store/src/reader.rs@@ -8432,6 +8432,41 @@ impl ReaderPool {.await}+ /// Creation instant of the oldest version of a page, as ISO-8601.+ ///+ /// `pages.created_at` is per version, so [`PageMeta::created_at`] is when+ /// the *latest* version was written. Every version of a page shares+ /// `(workspace_id, project_id, path)`; this returns the earliest of them,+ /// which is when the page itself first appeared. Keyed by ids, so a+ /// same-path page in another project never contributes.+ ///+ /// # Errors+ /// Propagates any SQL or pool error.+ pub async fn page_first_created_at(+ &self,+ workspace_id: WorkspaceId,+ project_id: ProjectId,+ page_path: &str,+ ) -> StoreResult<Option<String>> {+ let page_path = page_path.to_owned();+ self.with_conn(move |conn| {+ let first_us: Option<i64> = conn.query_row(+ "SELECT MIN(created_at) FROM pages \+ WHERE workspace_id = ?1 AND project_id = ?2 AND path = ?3",+ params![+ workspace_id.as_bytes().to_vec(),+ project_id.as_bytes().to_vec(),+ page_path+ ],+ |row| row.get(0),+ )?;+ Ok(first_us+ .and_then(|us| jiff::Timestamp::from_microsecond(us).ok())+ .map(|ts| ts.to_string()))+ })+ .await+ }+/// Fetch the latest version's stored body/title/frontmatter for a page by/// `(workspace_id, project_id, path)`. Used as a DB-backed fallback for/// `memory_read_page` when the on-disk markdown read fails (index/diskdiff --git a/crates/ai-memory-store/tests/suite/mod.rs b/crates/ai-memory-store/tests/suite/mod.rsindex 8c01a37e..1e1db06d 100644--- a/crates/ai-memory-store/tests/suite/mod.rs+++ b/crates/ai-memory-store/tests/suite/mod.rs@@ -16,6 +16,7 @@ mod handoff_ownership;mod identity_resolution;mod most_recently_active_scope;mod multi_session;+mod page_first_created;mod pinned_pages;mod profile;mod project_authz;diff --git a/crates/ai-memory-store/tests/suite/page_first_created.rs b/crates/ai-memory-store/tests/suite/page_first_created.rsnew file mode 100644index 00000000..cb048256--- /dev/null+++ b/crates/ai-memory-store/tests/suite/page_first_created.rs@@ -0,0 +1,121 @@+//! `ReaderPool::page_first_created_at`: the page-level creation instant behind+//! the web header's "Created".+//!+//! Invariants under test:+//! - **Oldest version wins.** `pages.created_at` is per version, so a page+//! with several versions reports the first one, not the latest.+//! - **Scoped by `(workspace_id, project_id, path)`.** A same-path page in+//! another project never moves the date.++use ai_memory_core::{NewPage, PagePath, ProjectId, Tier, WorkspaceId};+use ai_memory_store::Store;++fn page(ws: WorkspaceId, proj: ProjectId, path: &str, body: &str) -> NewPage {+ NewPage {+ workspace_id: ws,+ project_id: proj,+ path: PagePath::new(path).unwrap(),+ title: path.to_string(),+ body: body.into(),+ tier: Tier::Semantic,+ frontmatter_json: serde_json::json!({}),+ pinned: false,+ links: Vec::new(),+ author_id: None,+ expires_at: None,+ entities: Vec::new(),+ evidence: Vec::new(),+ }+}++fn set_created_at(tmp: &tempfile::TempDir, proj: ProjectId, body: &str, us: i64) {+ let conn = rusqlite::Connection::open(tmp.path().join("db/memory.sqlite")).unwrap();+ conn.pragma_update(None, "busy_timeout", 5_000).unwrap();+ let n = conn+ .execute(+ "UPDATE pages SET created_at = ?1 WHERE project_id = ?2 AND body = ?3",+ rusqlite::params![us, proj.as_bytes(), body],+ )+ .unwrap();+ assert_eq!(n, 1, "exactly one version has body {body:?}");+}++#[tokio::test]+async fn first_created_is_the_oldest_version_and_stays_in_its_project() {+ let tmp = tempfile::tempdir().unwrap();+ let store = Store::open(tmp.path()).unwrap();+ let ws = store+ .writer+ .get_or_create_workspace("default".to_string())+ .await+ .unwrap();+ let app = store+ .writer+ .get_or_create_project(ws, "app".to_string(), None)+ .await+ .unwrap();+ let other = store+ .writer+ .get_or_create_project(ws, "other".to_string(), None)+ .await+ .unwrap();++ for body in ["v1", "v2", "v3"] {+ store+ .writer+ .upsert_page(page(ws, app, "notes/a.md", body))+ .await+ .unwrap();+ }+ // Control: a single-version page reports its own (only) creation time.+ store+ .writer+ .upsert_page(page(ws, app, "notes/single.md", "only"))+ .await+ .unwrap();+ // Same path in another project, older than every `app` version: it must+ // not leak into the `app` answer.+ store+ .writer+ .upsert_page(page(ws, other, "notes/a.md", "foreign"))+ .await+ .unwrap();++ const DAY_US: i64 = 86_400_000_000;+ let now = jiff::Timestamp::now().as_microsecond();+ set_created_at(&tmp, app, "v1", now - 30 * DAY_US);+ set_created_at(&tmp, app, "v2", now - 10 * DAY_US);+ set_created_at(&tmp, app, "v3", now - DAY_US);+ set_created_at(&tmp, other, "foreign", now - 90 * DAY_US);+ set_created_at(&tmp, app, "only", now - 5 * DAY_US);++ let iso = |us: i64| jiff::Timestamp::from_microsecond(us).unwrap().to_string();++ let first = store+ .reader+ .page_first_created_at(ws, app, "notes/a.md")+ .await+ .unwrap();+ assert_eq!(first, Some(iso(now - 30 * DAY_US)));++ let single = store+ .reader+ .page_first_created_at(ws, app, "notes/single.md")+ .await+ .unwrap();+ assert_eq!(single, Some(iso(now - 5 * DAY_US)));++ let foreign = store+ .reader+ .page_first_created_at(ws, other, "notes/a.md")+ .await+ .unwrap();+ assert_eq!(foreign, Some(iso(now - 90 * DAY_US)));++ let missing = store+ .reader+ .page_first_created_at(ws, app, "notes/none.md")+ .await+ .unwrap();+ assert_eq!(missing, None);+}diff --git a/crates/ai-memory-web/Cargo.toml b/crates/ai-memory-web/Cargo.tomlindex 2c00906b..90978bc7 100644--- a/crates/ai-memory-web/Cargo.toml+++ b/crates/ai-memory-web/Cargo.toml@@ -34,6 +34,7 @@ anyhow.workspace = truesha2.workspace = true[dev-dependencies]+rusqlite.workspace = truetempfile.workspace = truetower.workspace = truediff --git a/crates/ai-memory-web/src/routes/page.rs b/crates/ai-memory-web/src/routes/page.rsindex be3ea857..3d94494e 100644--- a/crates/ai-memory-web/src/routes/page.rs+++ b/crates/ai-memory-web/src/routes/page.rs@@ -32,6 +32,16 @@ pub(crate) async fn handler(Err(_) => return StatusCode::INTERNAL_SERVER_ERROR.into_response(),};+ // `created_at` is per version; the header's "Created" is the first one.+ let created_at = match state+ .reader+ .page_first_created_at(meta.workspace_id, meta.project_id, &meta.path)+ .await+ {+ Ok(first) => first.unwrap_or_else(|| meta.created_at.clone()),+ Err(_) => return StatusCode::INTERNAL_SERVER_ERROR.into_response(),+ };+let page_path = match PagePath::new(&path) {Ok(p) => p,Err(_) => return StatusCode::BAD_REQUEST.into_response(),@@ -83,7 +93,7 @@ pub(crate) async fn handler(tier: meta.tier,pinned: meta.pinned,updated_relative: humanize(&meta.updated_at),- created_relative: humanize(&meta.created_at),+ created_relative: humanize(&created_at),supersedes_path,supersedes_href,body_html,diff --git a/crates/ai-memory-web/tests/suite/routes.rs b/crates/ai-memory-web/tests/suite/routes.rsindex b43e3d83..a1c4eb57 100644--- a/crates/ai-memory-web/tests/suite/routes.rs+++ b/crates/ai-memory-web/tests/suite/routes.rs@@ -4145,3 +4145,68 @@ async fn api_recent_incremental_rechecks_restricted_scope_on_cursor() {"a cursor cannot retain access after its user's grant is revoked");}++#[tokio::test]+async fn web_page_view_created_is_the_first_versions_date() {+ let (tmp, store, wiki) = setup().await;+ let ws = store+ .writer+ .get_or_create_workspace("default")+ .await+ .unwrap();+ let proj = store+ .writer+ .get_or_create_project(ws, "scratch", None)+ .await+ .unwrap();+ for body in ["first", "second", "third"] {+ wiki.write_page(wiki_req(ws, proj, "notes/versions.md", body))+ .await+ .unwrap();+ }+ wiki.write_page(wiki_req(ws, proj, "notes/single.md", "only"))+ .await+ .unwrap();++ // Age the superseded versions; the latest keeps its fresh timestamp.+ let conn = rusqlite::Connection::open(tmp.path().join("db/memory.sqlite")).unwrap();+ conn.pragma_update(None, "busy_timeout", 5_000).unwrap();+ let aged = jiff::Timestamp::now().as_microsecond() - 40 * 86_400_000_000;+ let n = conn+ .execute(+ "UPDATE pages SET created_at = ?1 \+ WHERE project_id = ?2 AND path = 'notes/versions.md' AND is_latest = 0",+ rusqlite::params![aged, proj.as_bytes()],+ )+ .unwrap();+ assert_eq!(n, 2, "two superseded versions");++ let app = router(store.reader.clone(), wiki.clone());+ let get = |uri: &'static str| {+ let app = app.clone();+ async move {+ let req = Request::builder().uri(uri).body(Body::empty()).unwrap();+ let resp = app.oneshot(req).await.unwrap();+ assert_eq!(resp.status(), StatusCode::OK);+ let body = axum::body::to_bytes(resp.into_body(), usize::MAX)+ .await+ .unwrap();+ String::from_utf8(body.to_vec()).unwrap()+ }+ };++ let text = get("/w/default/scratch/p/notes/versions.md").await;+ assert!(+ text.contains("Created 1 month ago"),+ "Created should be the oldest version's date: {text}"+ );+ assert!(+ text.contains("Updated just now"),+ "Updated stays the latest version's date: {text}"+ );+ let text = get("/w/default/scratch/p/notes/single.md").await;+ assert!(+ text.contains("Created just now"),+ "a single-version page keeps its own date: {text}"+ );+}