MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / _backlink_summary_pages

Function _backlink_summary_pages

openkb/agent/compiler.py:1211–1238  ·  view source on GitHub ↗

Append missing ``[[{page_dir}/slug]]`` wikilinks to the summary page. Closes the bidirectional link the pages already hold toward the summary, inserting them under ``section`` (created if absent). Shared by the concept and entity summary-backlink wrappers below.

(
    wiki_dir: Path,
    doc_name: str,
    slugs: list[str],
    *,
    page_dir: str,
    section: str,
)

Source from the content-addressed store, hash-verified

1209
1210
1211def _backlink_summary_pages(
1212 wiki_dir: Path,
1213 doc_name: str,
1214 slugs: list[str],
1215 *,
1216 page_dir: str,
1217 section: str,
1218) -> None:
1219 """Append missing ``[[{page_dir}/slug]]`` wikilinks to the summary page.
1220
1221 Closes the bidirectional link the pages already hold toward the summary,
1222 inserting them under ``section`` (created if absent). Shared by the
1223 concept and entity summary-backlink wrappers below.
1224 """
1225 summary_path = wiki_dir / "summaries" / f"{doc_name}.md"
1226 if not summary_path.exists():
1227 return
1228
1229 text = summary_path.read_text(encoding="utf-8")
1230 missing = [slug for slug in slugs if f"[[{page_dir}/{slug}]]" not in text]
1231 if not missing:
1232 return
1233
1234 lines = text.split("\n")
1235 _ensure_h2_section(lines, section, quiet=True)
1236 for slug in reversed(missing):
1237 _insert_section_entry(lines, section, f"- [[{page_dir}/{slug}]]")
1238 atomic_write_text(summary_path, "\n".join(lines))
1239
1240
1241def _backlink_pages(

Callers 2

_backlink_summaryFunction · 0.85

Calls 3

atomic_write_textFunction · 0.90
_ensure_h2_sectionFunction · 0.85
_insert_section_entryFunction · 0.85

Tested by

no test coverage detected