Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors
Rust
fix(consolidate): stop prompting for cross-scope wikilinks to pages that don't exist
Peterson Salme3abaa6678097
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 19ff988c..85821214 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0## [Unreleased]### Fixed+- Fixed consolidation inventing `[[_global:…]]` and `[[project:…]]` wikilinks to+ pages that never existed, which `ai-memory lint` then reported as+ `broken_link`. The single, batch and bootstrap prompts told the model that a+ missing link target was acceptable and gave it no list of cross-scope pages,+ so it invented targets to meet the 2-5 link guidance. They now allow a+ `project:` or `_global:` link only when the exact target appears in the input,+ matching what lint accepts; a missing same-project target stays a pending+ link. (#1207)- Fixed the web UI answering HTTP 500 when a signed-in viewer opened a projector page by a name that two projects answer to. The page and project routesnow return a 400 that names the clash, matching the API and MCP surfaces.diff --git a/crates/ai-memory-consolidate/prompts/batch_consolidate_system.md b/crates/ai-memory-consolidate/prompts/batch_consolidate_system.mdindex 40ce7ad7..04d08d1b 100644--- a/crates/ai-memory-consolidate/prompts/batch_consolidate_system.md+++ b/crates/ai-memory-consolidate/prompts/batch_consolidate_system.md@@ -75,17 +75,20 @@ input — reference it inline with a wikilink:page *path* relative to the project root(e.g. `[[decisions/0003-no-vector-db]]`), not the display title.- `[[project:page-path]]` — a page in a sibling project. Use it- when the work clearly concerns another project that is named in- the input — e.g. a fix in this project whose root cause lives in- the sibling project `billing` links `[[billing:audio-pipeline]]`.- Never invent project names.+ only when the input names both that project and that page path+ — e.g. a fix in this project whose root cause lives in the+ sibling project `billing` links `[[billing:audio-pipeline]]`.+ Never invent project names or page paths.- `[[_global:page-path]]` — a cross-cutting principle, convention,- or trap that applies to every project.--A link whose target does not exist yet is acceptable — it is-recorded as a pending link and resolves automatically when the-page appears. 2-5 well-chosen links per page beat exhaustive-linking; zero links should be rare.+ or trap that applies to every project. Use it only when that+ exact path appears in the input.++A same-project link whose target does not exist yet is acceptable+— it is recorded as a pending link and resolves automatically when+the page appears. A `project:` or `_global:` link is not: lint+reports a missing cross-scope target as broken. 2-5 well-chosen+links per page beat exhaustive linking; zero links should be rare,+but never pad with a cross-scope link you cannot see in the input.## OUTPUT LANGUAGEdiff --git a/crates/ai-memory-consolidate/prompts/bootstrap_system.md b/crates/ai-memory-consolidate/prompts/bootstrap_system.mdindex c3e329b6..24728af2 100644--- a/crates/ai-memory-consolidate/prompts/bootstrap_system.md+++ b/crates/ai-memory-consolidate/prompts/bootstrap_system.md@@ -66,17 +66,20 @@ input — reference it inline with a wikilink:page *path* relative to the project root(e.g. `[[decisions/0003-no-vector-db]]`), not the display title.- `[[project:page-path]]` — a page in a sibling project. Use it- when the work clearly concerns another project that is named in- the input — e.g. a fix in this project whose root cause lives in- the sibling project `billing` links `[[billing:audio-pipeline]]`.- Never invent project names.+ only when the input names both that project and that page path+ — e.g. a fix in this project whose root cause lives in the+ sibling project `billing` links `[[billing:audio-pipeline]]`.+ Never invent project names or page paths.- `[[_global:page-path]]` — a cross-cutting principle, convention,- or trap that applies to every project.--A link whose target does not exist yet is acceptable — it is-recorded as a pending link and resolves automatically when the-page appears. 2-5 well-chosen links per page beat exhaustive-linking; zero links should be rare.+ or trap that applies to every project. Use it only when that+ exact path appears in the input.++A same-project link whose target does not exist yet is acceptable+— it is recorded as a pending link and resolves automatically when+the page appears. A `project:` or `_global:` link is not: lint+reports a missing cross-scope target as broken. 2-5 well-chosen+links per page beat exhaustive linking; zero links should be rare,+but never pad with a cross-scope link you cannot see in the input.## OUTPUT LANGUAGEdiff --git a/crates/ai-memory-consolidate/prompts/single_consolidate_system.md b/crates/ai-memory-consolidate/prompts/single_consolidate_system.mdindex f02b02bd..cc35a2e7 100644--- a/crates/ai-memory-consolidate/prompts/single_consolidate_system.md+++ b/crates/ai-memory-consolidate/prompts/single_consolidate_system.md@@ -71,17 +71,20 @@ input — reference it inline with a wikilink:page *path* relative to the project root(e.g. `[[decisions/0003-no-vector-db]]`), not the display title.- `[[project:page-path]]` — a page in a sibling project. Use it- when the work clearly concerns another project that is named in- the input — e.g. a fix in this project whose root cause lives in- the sibling project `billing` links `[[billing:audio-pipeline]]`.- Never invent project names.+ only when the input names both that project and that page path+ — e.g. a fix in this project whose root cause lives in the+ sibling project `billing` links `[[billing:audio-pipeline]]`.+ Never invent project names or page paths.- `[[_global:page-path]]` — a cross-cutting principle, convention,- or trap that applies to every project.--A link whose target does not exist yet is acceptable — it is-recorded as a pending link and resolves automatically when the-page appears. 2-5 well-chosen links per page beat exhaustive-linking; zero links should be rare.+ or trap that applies to every project. Use it only when that+ exact path appears in the input.++A same-project link whose target does not exist yet is acceptable+— it is recorded as a pending link and resolves automatically when+the page appears. A `project:` or `_global:` link is not: lint+reports a missing cross-scope target as broken. 2-5 well-chosen+links per page beat exhaustive linking; zero links should be rare,+but never pad with a cross-scope link you cannot see in the input.## OUTPUT LANGUAGEdiff --git a/crates/ai-memory-consolidate/src/bootstrap.rs b/crates/ai-memory-consolidate/src/bootstrap.rsindex b75872c2..798deed6 100644--- a/crates/ai-memory-consolidate/src/bootstrap.rs+++ b/crates/ai-memory-consolidate/src/bootstrap.rs@@ -1802,6 +1802,14 @@ mod tests {assert!(parse_since_to_epoch("garbage").is_none());}+ #[test]+ fn bootstrap_system_prompt_limits_cross_scope_links_to_input_targets() {+ assert!(SYSTEM_PROMPT.contains("Never invent project names or page paths"));+ assert!(SYSTEM_PROMPT.contains("only when that\n exact path appears in the input"));+ assert!(SYSTEM_PROMPT.contains("never pad with a cross-scope link"));+ assert!(!SYSTEM_PROMPT.contains("A link whose target does not exist yet is acceptable"));+ }+#[test]fn bootstrap_system_prompt_requires_graph_links_and_input_language() {assert!(SYSTEM_PROMPT.contains("## WIKILINKS"));diff --git a/crates/ai-memory-consolidate/src/consolidator.rs b/crates/ai-memory-consolidate/src/consolidator.rsindex 9be9d776..adc337a2 100644--- a/crates/ai-memory-consolidate/src/consolidator.rs+++ b/crates/ai-memory-consolidate/src/consolidator.rs@@ -2958,6 +2958,30 @@ mod tests {}}+ #[test]+ fn consolidation_system_prompts_limit_cross_scope_links_to_input_targets() {+ // Lint reports a missing `project:` / `_global:` target as+ // `broken_link`, so the prompts must not license inventing one.+ for (name, prompt) in [("single", SYSTEM_PROMPT), ("batch", BATCH_SYSTEM_PROMPT)] {+ assert!(+ prompt.contains("Never invent project names or page paths"),+ "{name} prompt"+ );+ assert!(+ prompt.contains("only when that\n exact path appears in the input"),+ "{name} prompt"+ );+ assert!(+ prompt.contains("never pad with a cross-scope link"),+ "{name} prompt"+ );+ assert!(+ !prompt.contains("A link whose target does not exist yet is acceptable"),+ "{name} prompt must scope the pending-link allowance to the same project"+ );+ }+ }+#[test]fn build_request_elides_raw_observations_from_current_body() {let raw_dump = (0..2_000)