Resolve a heading label, node id or ``path::Heading`` to one section node. An explicit node id takes precedence. For a name or path query, retry against the section nodes so a code symbol cannot hide a heading match.
(G, query: str)
| 177 | |
| 178 | |
| 179 | def resolve_section_query(G, query: str) -> "tuple[str | None, str]": |
| 180 | """Resolve a heading label, node id or ``path::Heading`` to one section node. |
| 181 | |
| 182 | An explicit node id takes precedence. For a name or path query, retry |
| 183 | against the section nodes so a code symbol cannot hide a heading match. |
| 184 | """ |
| 185 | from graphify.serve import _is_ambiguity_refusal, _resolve_single_node |
| 186 | |
| 187 | nid, err = _resolve_single_node(G, query) |
| 188 | if nid is not None and (query == nid or is_section_node(G.nodes[nid])): |
| 189 | return nid, "" |
| 190 | sections = G.subgraph([n for n, d in G.nodes(data=True) if is_section_node(d)]) |
| 191 | # A subgraph view shares G.graph, so it would reuse the full graph's search |
| 192 | # caches (ids of nodes not in the view) or store its own over the full |
| 193 | # graph's. Keep public graph metadata and the logical direction flag, but |
| 194 | # discard other private state so future caches cannot leak into this view. |
| 195 | sections.graph = { |
| 196 | k: v for k, v in G.graph.items() |
| 197 | if not k.startswith("_") or k in _SECTION_VIEW_GRAPH_KEYS |
| 198 | } |
| 199 | sec_nid, sec_err = _resolve_single_node(sections, query) |
| 200 | if sec_nid is not None: |
| 201 | return sec_nid, "" |
| 202 | if sec_err and _is_ambiguity_refusal(sec_err): |
| 203 | return None, sec_err |
| 204 | return nid, err or "" |