answer: derive non-rpi nodes from snapshot
This commit is contained in:
parent
2c7490288d
commit
b019934db2
@ -532,6 +532,11 @@ class AnswerEngine:
|
||||
model=plan.model,
|
||||
tag="evidence_fix",
|
||||
)
|
||||
|
||||
if "raspberry" in lowered_question and "not" in lowered_question:
|
||||
non_rpi = _non_rpi_nodes(summary)
|
||||
if non_rpi:
|
||||
reply = _format_hardware_groups(non_rpi, "Non-Raspberry Pi nodes")
|
||||
if unknown_nodes or unknown_namespaces:
|
||||
refreshed_nodes = _find_unknown_nodes(reply, allowed_nodes)
|
||||
refreshed_namespaces = _find_unknown_namespaces(reply, allowed_namespaces)
|
||||
@ -1639,6 +1644,31 @@ def _line_starting_with(lines: list[str], prefix: str) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
def _non_rpi_nodes(summary: dict[str, Any]) -> dict[str, list[str]]:
|
||||
hardware = summary.get("hardware_by_node") if isinstance(summary, dict) else None
|
||||
if not isinstance(hardware, dict):
|
||||
return {}
|
||||
grouped: dict[str, list[str]] = {}
|
||||
for node, hw in hardware.items():
|
||||
if not isinstance(node, str) or not isinstance(hw, str):
|
||||
continue
|
||||
if hw.startswith("rpi"):
|
||||
continue
|
||||
grouped.setdefault(hw, []).append(node)
|
||||
for nodes in grouped.values():
|
||||
nodes.sort()
|
||||
return grouped
|
||||
|
||||
|
||||
def _format_hardware_groups(groups: dict[str, list[str]], label: str) -> str:
|
||||
if not groups:
|
||||
return ""
|
||||
parts = []
|
||||
for hw, nodes in sorted(groups.items()):
|
||||
parts.append(f"{hw} ({', '.join(nodes)})")
|
||||
return f\"{label}: \" + \"; \".join(parts) + \".\"
|
||||
|
||||
|
||||
def _lexicon_context(summary: dict[str, Any]) -> str: # noqa: C901
|
||||
if not isinstance(summary, dict):
|
||||
return ""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user