Restore character facts in H3 ref context

This commit is contained in:
2026-08-27 07:58:05 +00:00
parent 32fc9b39df
commit a660919425
2 changed files with 82 additions and 1 deletions
+55
View File
@@ -4239,6 +4239,58 @@ def _reference_sentence(value):
return text
def _reference_positive_int(value):
text = _reference_text(value)
if not text:
return None
try:
parsed = int(text)
except (TypeError, ValueError):
return None
return parsed if parsed > 0 else None
def _reference_height_text(facts):
feet = _reference_text((facts or {}).get("height_feet"))
inches = _reference_text((facts or {}).get("height_inches"))
if feet and inches:
return f"{feet} foot {inches}"
if feet:
return f"{feet} foot"
if inches:
return f"{inches} inch"
return ""
def _reference_fact_sentence(ref, label):
facts = dict(ref.get("facts") or {})
bits = []
gender = _reference_text(facts.get("gender"))
age = _reference_positive_int(facts.get("age"))
nationality = _reference_text(facts.get("nationality"))
occupation = _reference_text(facts.get("occupation"))
accent = _reference_text(facts.get("accent"))
height = _reference_height_text(facts)
aliases = [_reference_text(alias) for alias in (ref.get("aliases") or []) if _reference_text(alias)]
if aliases:
bits.append(f"also known as {aliases[0]}")
if gender:
bits.append(gender)
if age is not None:
bits.append(f"{age} years old")
if nationality:
bits.append(nationality)
if occupation:
bits.append(f"works as {occupation}")
if height:
bits.append(f"{height} tall")
if accent:
bits.append(f"speaks with a {accent} accent")
if not bits:
return ""
return f"Character facts for {label}: " + ", ".join(bits) + "."
def _reference_name_keys(ref):
names = []
for key in ("name", "id"):
@@ -4305,12 +4357,15 @@ def _reference_context_for_text(text, ref_slots):
description = _reference_sentence(ref.get("description"))
wardrobe = _reference_sentence(ref.get("wardrobe"))
general = _reference_sentence(ref.get("general"))
facts = _reference_fact_sentence(ref, label)
if ref.get("kind") == "location":
if description:
parts.append(f"Location context for {label}: {description}")
if general:
parts.append(f"Location notes for {label}: {general}")
continue
if facts:
parts.append(facts)
if description:
parts.append(f"Persistent appearance for {label}: {description}")
if wardrobe: