Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(web): say when search results are cut at 50
Peterson Salme87350c91bdc7
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 6bf29b1a..8919656c 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 search page printing "50 results" with no hint when more+ pages matched. It now says it shows the first 50 results and suggests+ refining the search. (#NNNN)## [2.6.5] - 2026-10-12diff --git a/crates/ai-memory-web/src/routes/search.rs b/crates/ai-memory-web/src/routes/search.rsindex a4926927..66623ef8 100644--- a/crates/ai-memory-web/src/routes/search.rs+++ b/crates/ai-memory-web/src/routes/search.rs@@ -20,6 +20,10 @@ pub(crate) struct SearchParams {pub q: String,}+/// Most results the search page renders. One more is requested so a cut-off+/// result set can be told apart from one that happens to have exactly this many.+const MAX_RESULTS: usize = 50;+/// Handler for `GET /search?q=…`.////// Searches only the repositories the viewer may read (#708) — see@@ -32,22 +36,23 @@ pub(crate) async fn handler() -> Result<Html<String>, StatusCode> {let query = params.q.trim().to_owned();- let hits = if query.is_empty() {- Vec::new()+ let (hits, truncated) = if query.is_empty() {+ (Vec::new(), false)} else {let raw = state.reader.search_pages_with_meta(query.clone(),- 50,+ MAX_RESULTS + 1,None,viewer.map(|axum::Extension(viewer)| viewer.user()),).await.map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;- let mut results = Vec::with_capacity(raw.len());- for h in raw {+ let truncated = raw.len() > MAX_RESULTS;+ let mut results = Vec::with_capacity(raw.len().min(MAX_RESULTS));+ for h in raw.into_iter().take(MAX_RESULTS) {let path = h.path.as_str().to_owned();let href = page_href(&h.workspace_name, &h.project_name, &path);results.push(SearchHit {@@ -59,7 +64,7 @@ pub(crate) async fn handler(snippet: markdown::escape_snippet(&h.snippet),});}- results+ (results, truncated)};let hit_count = hits.len();@@ -67,6 +72,8 @@ pub(crate) async fn handler(query,hits,hit_count,+ truncated,+ max_results: MAX_RESULTS,}.render().map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;diff --git a/crates/ai-memory-web/src/templates.rs b/crates/ai-memory-web/src/templates.rsindex a985009e..2ae5ce50 100644--- a/crates/ai-memory-web/src/templates.rs+++ b/crates/ai-memory-web/src/templates.rs@@ -277,6 +277,10 @@ pub(crate) struct SearchView {pub hits: Vec<SearchHit>,/// Pre-computed hit count for display (avoids needing `|length` filter).pub hit_count: usize,+ /// More matches existed than `max_results`; the list is cut.+ pub truncated: bool,+ /// Most rows the page renders.+ pub max_results: usize,}// ---------------------------------------------------------------------------diff --git a/crates/ai-memory-web/templates/search.html b/crates/ai-memory-web/templates/search.htmlindex b2576faf..19f13645 100644--- a/crates/ai-memory-web/templates/search.html+++ b/crates/ai-memory-web/templates/search.html@@ -31,7 +31,11 @@{% else if hits.is_empty() %}<p class="text-sm text-slate-500 dark:text-slate-400">No results for <strong>{{ query }}</strong>.</p>{% else %}+{% if truncated %}+<p class="text-sm text-slate-500 dark:text-slate-400 mb-4">Showing the first {{ max_results }} results. Refine your search to narrow them.</p>+{% else %}<p class="text-sm text-slate-500 dark:text-slate-400 mb-4">{{ hit_count }} result{% if hit_count != 1 %}s{% endif %}</p>+{% endif %}<ul class="divide-y divide-slate-100 dark:divide-slate-800">{% for hit in hits %}<li class="py-4">diff --git a/crates/ai-memory-web/tests/suite/routes.rs b/crates/ai-memory-web/tests/suite/routes.rsindex b43e3d83..fd0d282e 100644--- a/crates/ai-memory-web/tests/suite/routes.rs+++ b/crates/ai-memory-web/tests/suite/routes.rs@@ -405,6 +405,70 @@ async fn smoke_search_returns_200() {);}+/// Seeds `n` pages matching one term and returns the `/search` body for it.+async fn search_body_with_pages(n: usize) -> String {+ 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 i in 0..n {+ store+ .writer+ .upsert_page(new_page(+ ws,+ proj,+ &format!("p{i}.md"),+ &format!("Cap Page {i}"),+ "capnoticeterm",+ ))+ .await+ .unwrap();+ }+ let app = router(store.reader.clone(), wiki.clone());+ let req = Request::builder()+ .uri("/search?q=capnoticeterm")+ .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()+}++const CUT_NOTICE: &str = "Showing the first 50 results. Refine your search to narrow them.";++#[tokio::test]+async fn search_over_the_cap_shows_truncation_notice() {+ let text = search_body_with_pages(51).await;+ assert!(text.contains(CUT_NOTICE), "missing notice");+ assert!(!text.contains("51 results") && !text.contains(">50 results<"));+ assert_eq!(text.matches("Cap Page ").count(), 50, "rows rendered");+}++#[tokio::test]+async fn search_at_the_cap_shows_plain_count() {+ let text = search_body_with_pages(50).await;+ assert!(!text.contains(CUT_NOTICE), "unexpected notice");+ assert!(text.contains("50 results"));+ assert_eq!(text.matches("Cap Page ").count(), 50, "rows rendered");+}++#[tokio::test]+async fn search_under_the_cap_shows_plain_count() {+ let text = search_body_with_pages(3).await;+ assert!(!text.contains(CUT_NOTICE), "unexpected notice");+ assert!(text.contains("3 results"));+}+#[tokio::test]async fn web_links_percent_encode_route_segments() {let (_tmp, store, wiki) = setup().await;