@@ -299,13 +299,14 @@ def _get_section_bounds(lines: list[str], heading: str) -> tuple[int, int] | Non
299299
300300
301301def _section_contains_link (lines : list [str ], heading : str , link : str ) -> bool :
302- """Check whether a wikilink already exists inside the named section."""
302+ """Check whether an index entry already exists inside the named section."""
303303 bounds = _get_section_bounds (lines , heading )
304304 if bounds is None :
305305 return False
306306
307307 start , end = bounds
308- return any (link in line for line in lines [start :end ])
308+ entry_prefix = f"- { link } "
309+ return any (line .startswith (entry_prefix ) for line in lines [start :end ])
309310
310311
311312def _replace_section_entry (lines : list [str ], heading : str , link : str , entry : str ) -> bool :
@@ -315,8 +316,9 @@ def _replace_section_entry(lines: list[str], heading: str, link: str, entry: str
315316 return False
316317
317318 start , end = bounds
319+ entry_prefix = f"- { link } "
318320 for i in range (start , end ):
319- if link in lines [i ]:
321+ if lines [i ]. startswith ( entry_prefix ) :
320322 lines [i ] = entry
321323 return True
322324 return False
@@ -509,7 +511,6 @@ def _backlink_concepts(wiki_dir: Path, doc_name: str, concept_slugs: list[str])
509511 text += f"\n \n ## Related Documents\n - { link } \n "
510512 path .write_text (text , encoding = "utf-8" )
511513
512-
513514def _update_index (
514515 wiki_dir : Path , doc_name : str , concept_names : list [str ],
515516 doc_brief : str = "" , concept_briefs : dict [str , str ] | None = None ,
@@ -519,7 +520,7 @@ def _update_index(
519520
520521 When ``doc_brief`` or entries in ``concept_briefs`` are provided, entries
521522 are written as ``- [[link]] (type) — brief text``. Existing entries are
522- detected within their own section by the link part only and skipped to
523+ detected within their own section by exact entry prefix and skipped to
523524 avoid duplicates.
524525 ``doc_type`` is ``"short"`` or ``"pageindex"`` — shown in the entry so the
525526 query agent knows how to access detailed content.
@@ -534,8 +535,7 @@ def _update_index(
534535 encoding = "utf-8" ,
535536 )
536537
537- text = index_path .read_text (encoding = "utf-8" )
538- lines = text .split ("\n " )
538+ lines = index_path .read_text (encoding = "utf-8" ).split ("\n " )
539539
540540 doc_link = f"[[summaries/{ doc_name } ]]"
541541 if not _section_contains_link (lines , "## Documents" , doc_link ):
@@ -555,8 +555,7 @@ def _update_index(
555555 else :
556556 _insert_section_entry (lines , "## Concepts" , concept_entry )
557557
558- text = "\n " .join (lines )
559- index_path .write_text (text , encoding = "utf-8" )
558+ index_path .write_text ("\n " .join (lines ), encoding = "utf-8" )
560559
561560
562561# ---------------------------------------------------------------------------
0 commit comments