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

Function _backlink_pages

openkb/agent/compiler.py:1241–1263  ·  view source on GitHub ↗

Append the source summary wikilink to each page under '## Related Documents'. Shared by the concept and entity page-backlink wrappers.

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

Source from the content-addressed store, hash-verified

1239
1240
1241def _backlink_pages(
1242 wiki_dir: Path,
1243 doc_name: str,
1244 slugs: list[str],
1245 *,
1246 page_dir: str,
1247) -> None:
1248 """Append the source summary wikilink to each page under '## Related
1249 Documents'. Shared by the concept and entity page-backlink wrappers."""
1250 link = f"[[summaries/{doc_name}]]"
1251 pages_dir = wiki_dir / page_dir
1252
1253 for slug in slugs:
1254 path = pages_dir / f"{slug}.md"
1255 if not path.exists():
1256 continue
1257 text = path.read_text(encoding="utf-8")
1258 if link in text:
1259 continue
1260 lines = text.split("\n")
1261 _ensure_h2_section(lines, "## Related Documents", quiet=True)
1262 _insert_section_entry(lines, "## Related Documents", f"- {link}")
1263 atomic_write_text(path, "\n".join(lines))
1264
1265
1266def _backlink_summary(wiki_dir: Path, doc_name: str, concept_slugs: list[str]) -> None:

Callers 2

_backlink_conceptsFunction · 0.85
_backlink_entitiesFunction · 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