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

Function _get_section_bounds

openkb/agent/compiler.py:784–798  ·  view source on GitHub ↗

Return the [start, end) bounds for a Markdown H2 section. Uses ``_iter_h2_headings`` so the same H2 detection that finds the target heading also determines the section's end (the next H2). A drifted ``"## Documents "`` matches ``"## Documents"`` because both sides are normalized.

(lines: list[str], heading: str)

Source from the content-addressed store, hash-verified

782
783
784def _get_section_bounds(lines: list[str], heading: str) -> tuple[int, int] | None:
785 """Return the [start, end) bounds for a Markdown H2 section.
786
787 Uses ``_iter_h2_headings`` so the same H2 detection that finds the
788 target heading also determines the section's end (the next H2). A
789 drifted ``"## Documents "`` matches ``"## Documents"`` because both
790 sides are normalized.
791 """
792 headings = _iter_h2_headings(lines)
793 for k, (idx, normalized) in enumerate(headings):
794 if normalized == heading:
795 start = idx + 1
796 end = headings[k + 1][0] if k + 1 < len(headings) else len(lines)
797 return start, end
798 return None
799
800
801def _ensure_h2_section(lines: list[str], heading: str, *, quiet: bool = False) -> None:

Callers 6

_ensure_h2_sectionFunction · 0.85
_section_contains_linkFunction · 0.85
_replace_section_entryFunction · 0.85
_insert_section_entryFunction · 0.85
_remove_section_entryFunction · 0.85

Calls 1

_iter_h2_headingsFunction · 0.85

Tested by

no test coverage detected