Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(wiki): stop demoting valid links on slug collisions and heal old demotion scars
Ruben Lütke7e9e71205e5b
diff --git a/jarvis/memory/wiki/curator.py b/jarvis/memory/wiki/curator.pyindex 3661a577eb..1ab2db8802 100644--- a/jarvis/memory/wiki/curator.py+++ b/jarvis/memory/wiki/curator.py@@ -44,6 +44,7 @@ from .protocols import (from .session_links import (_WIKILINK_RE,SlugIndex,+ promote_plaintext_links,rewrite_body_links,strip_dangling_wikilinks,)@@ -307,9 +308,15 @@ class WikiCurator:before_links = len(_WIKILINK_RE.findall(upd.new_body))body = strip_dangling_wikilinks(upd.new_body)body, _resolved = rewrite_body_links(body, index)+ # Heal old demotion scars: a plain-text ``dir/slug`` whose page+ # exists NOW (created after the original demotion) becomes a+ # [[link]] again, so lost graph edges recover on the next write.+ body, promoted = promote_plaintext_links(body, index)+ if promoted > 0:+ telemetry.inc("wiki_links_promoted", promoted)# Every closed link either survived as [[...]] (resolved) or was# demoted to plain text; the difference is the refusal count.- after_links = len(_WIKILINK_RE.findall(body))+ after_links = len(_WIKILINK_RE.findall(body)) - promotedrefused = before_links - after_linksif refused > 0:telemetry.inc("wiki_links_refused_dangling", refused)diff --git a/jarvis/memory/wiki/session_links.py b/jarvis/memory/wiki/session_links.pyindex e0cc32a23c..c0ac48217f 100644--- a/jarvis/memory/wiki/session_links.py+++ b/jarvis/memory/wiki/session_links.py@@ -124,6 +124,13 @@ class SlugIndex:if not slug:continuecanonical = f"{directory}/{slug}"+ # The bare-slug slot is single-valued (last directory wins), so a+ # slug living in TWO directories (entities/bugatti-divo AND+ # projects/bugatti-divo) used to make the dir-prefixed form of one+ # of them unresolvable — its valid [[link]] was demoted to plain+ # text on every write (live scar 2026-07-18). The dir-prefixed key+ # keeps each page addressable regardless of collisions.+ by_slug[canonical] = canonicalby_slug[slug] = canonical# The slug with hyphens turned to spaces resolves a Title-Case# mention even without an explicit alias ("personal-jarvis" then@@ -148,9 +155,13 @@ class SlugIndex:return Noneif "/" in target:+ canonical = self._by_slug.get(target)+ if canonical is not None:+ return canonical+ # Hand-built indexes may carry only bare-slug keys; trust the+ # prefix only when it matches the page's real directory.directory, _, bare = target.rpartition("/")canonical = self._by_slug.get(bare)- # Trust the prefix only when it matches the page's real directory.if canonical is not None and canonical == f"{directory}/{bare}":return canonicalreturn None@@ -200,6 +211,60 @@ def rewrite_body_links(text: str, index: SlugIndex) -> tuple[str, list[str]]:return new_text, resolved+# A demotion scar: a bare ``dir/slug`` page path in prose. Nobody writes+# these as ordinary text — they are what ``rewrite_body_links`` leaves behind+# when it demotes a link whose target did not exist at write time. The+# lookbehind/lookahead keep us out of URLs, longer paths, and backticked+# spans; the optional ``.md`` accepts the file-name spelling.+_PLAINTEXT_PATH_RE = re.compile(+ r"(?<![\w/.`-])"+ r"(entities|concepts|projects|sessions)/([a-z0-9](?:[a-z0-9-]*[a-z0-9])?)"+ r"(?:\.md)?"+ r"(?![\w/-])"+)+++def promote_plaintext_links(text: str, index: SlugIndex) -> tuple[str, int]:+ """Re-promote demoted plain-text page paths back into ``[[wikilinks]]``.++ Link demotion is one-way at write time: a ``[[entities/x]]`` written+ moments before ``entities/x.md`` existed survives as the plain text+ ``entities/x`` forever, and the graph edge stays lost even after the+ page is created. Any bare ``dir/slug`` occurrence that resolves to an+ existing page is wrapped back into a canonical link; text inside+ existing ``[[...]]`` spans and the leading frontmatter block are left+ untouched. Returns ``(new_text, promoted_count)``.++ Pure: regex only, no LLM call, no disk write (AP-9/AP-11).+ """+ promoted = 0++ def _wrap(match: re.Match[str]) -> str:+ nonlocal promoted+ canonical = index.resolve(f"{match.group(1)}/{match.group(2)}")+ if canonical is None:+ return match.group(0)+ promoted += 1+ return f"[[{canonical}]]"++ body_start = 0+ if text.startswith("---"):+ fm_end = text.find("\n---", 3)+ if fm_end != -1:+ body_start = text.find("\n", fm_end + 1)+ body_start = len(text) if body_start == -1 else body_start + 1++ head = text[:body_start]+ parts: list[str] = []+ last = body_start+ for existing in _WIKILINK_RE.finditer(text, body_start):+ parts.append(_PLAINTEXT_PATH_RE.sub(_wrap, text[last:existing.start()]))+ parts.append(existing.group(0))+ last = existing.end()+ parts.append(_PLAINTEXT_PATH_RE.sub(_wrap, text[last:]))+ return head + "".join(parts), promoted++def build_related_footer(*,hub_links: list[str],@@ -265,6 +330,7 @@ def relink_session_body(__all__ = ["SlugIndex","build_related_footer",+ "promote_plaintext_links","relink_session_body","rewrite_body_links","slugify",diff --git a/jarvis/memory/wiki/telemetry.py b/jarvis/memory/wiki/telemetry.pyindex 9b34251859..742b2bdade 100644--- a/jarvis/memory/wiki/telemetry.py+++ b/jarvis/memory/wiki/telemetry.py@@ -56,6 +56,7 @@ DEFAULT_COUNTERS: tuple[str, ...] = (# D2 (2026-06): session-page feed retirement + conversation-only feed."session_rollups_wiki_write_disabled","wiki_links_refused_dangling",+ "wiki_links_promoted","wiki_writes_blocked_pii","wiki_writes_blocked_truncated",# Wave-2 two-stage curator quality counters (B8). Decision names followdiff --git a/tests/unit/memory/wiki/test_session_links.py b/tests/unit/memory/wiki/test_session_links.pyindex f93f762279..67da308734 100644--- a/tests/unit/memory/wiki/test_session_links.py+++ b/tests/unit/memory/wiki/test_session_links.py@@ -22,6 +22,7 @@ import pytestfrom jarvis.memory.wiki.session_links import (SlugIndex,build_related_footer,+ promote_plaintext_links,relink_session_body,rewrite_body_links,slugify,@@ -209,6 +210,88 @@ def test_relink_clean_body_is_unchanged() -> None:assert new_body == body+def _colliding_index() -> SlugIndex:+ """One slug living in TWO directories — the live bugatti-divo layout."""+ return SlugIndex.from_pages([+ ("entities", "ruben", ["Ruben"]),+ ("entities", "bugatti-divo", ["Bugatti Divo"]),+ ("projects", "bugatti-divo", []),+ ])+++def test_dir_prefixed_resolve_survives_cross_directory_slug_collision() -> None:+ """Live scar 2026-07-18: entities/bugatti-divo AND projects/bugatti-divo+ both exist; the single-slot bare-slug map made ONE of the dir-prefixed+ forms unresolvable, so its valid [[link]] was demoted on every write."""+ index = _colliding_index()+ assert index.resolve("entities/bugatti-divo") == "entities/bugatti-divo"+ assert index.resolve("projects/bugatti-divo") == "projects/bugatti-divo"+++def test_rewrite_keeps_both_colliding_dir_prefixed_links() -> None:+ body = (+ "Owner of [[entities/bugatti-divo]]; "+ "purchase tracked in [[projects/bugatti-divo]]."+ )+ new_body, resolved = rewrite_body_links(body, _colliding_index())+ assert "[[entities/bugatti-divo]]" in new_body+ assert "[[projects/bugatti-divo]]" in new_body+ assert set(resolved) == {"entities/bugatti-divo", "projects/bugatti-divo"}+++# ---------------------------------------------------------------------------+# promote_plaintext_links — healing old demotion scars+# ---------------------------------------------------------------------------+++def test_promote_rewraps_existing_page_path() -> None:+ body = "## Relationships\n\n- entities/bugatti-divo — Owner.\n"+ new_body, promoted = promote_plaintext_links(body, _colliding_index())+ assert promoted == 1+ assert "- [[entities/bugatti-divo]] — Owner.\n" in new_body+++def test_promote_accepts_md_suffixed_spelling() -> None:+ body = "See projects/bugatti-divo.md for the purchase.\n"+ new_body, promoted = promote_plaintext_links(body, _colliding_index())+ assert promoted == 1+ assert "See [[projects/bugatti-divo]] for the purchase.\n" == new_body+++def test_promote_leaves_unknown_paths_alone() -> None:+ body = "- entities/never-created — gone.\n"+ new_body, promoted = promote_plaintext_links(body, _colliding_index())+ assert promoted == 0+ assert new_body == body+++def test_promote_never_touches_existing_links_or_frontmatter() -> None:+ body = (+ "---\n"+ "type: entity\n"+ "slug: ruben\n"+ "note: entities/bugatti-divo\n"+ "---\n"+ "\n"+ "- [[entities/bugatti-divo]] already linked\n"+ "- entities/bugatti-divo scar\n"+ )+ new_body, promoted = promote_plaintext_links(body, _colliding_index())+ assert promoted == 1+ assert "note: entities/bugatti-divo\n" in new_body # frontmatter untouched+ assert new_body.count("[[entities/bugatti-divo]]") == 2 # link + healed scar+++def test_promote_skips_backticked_and_url_spans() -> None:+ body = (+ "Run `entities/bugatti-divo` manually; "+ "see https://example.com/entities/bugatti-divo too.\n"+ )+ new_body, promoted = promote_plaintext_links(body, _colliding_index())+ assert promoted == 0+ assert new_body == body++def test_footer_order_is_deterministic() -> None:a = build_related_footer(hub_links=["entities/ruben", "projects/personal-jarvis"],