Read existing entity pages as compact lines for the plan call. Formats each as ``- {slug} ({type}, {n} sources) — {brief}``. The source count is the cross-document recurrence signal the LLM uses to decide create-vs-update and salience. Returns "(none yet)" when empty.
(wiki_dir: Path)
| 736 | |
| 737 | |
| 738 | def _read_entity_briefs(wiki_dir: Path) -> str: |
| 739 | """Read existing entity pages as compact lines for the plan call. |
| 740 | |
| 741 | Formats each as ``- {slug} ({type}, {n} sources) — {brief}``. The source |
| 742 | count is the cross-document recurrence signal the LLM uses to decide |
| 743 | create-vs-update and salience. Returns "(none yet)" when empty. |
| 744 | """ |
| 745 | entities_dir = wiki_dir / "entities" |
| 746 | if not entities_dir.exists(): |
| 747 | return "(none yet)" |
| 748 | |
| 749 | md_files = sorted(entities_dir.glob("*.md")) |
| 750 | if not md_files: |
| 751 | return "(none yet)" |
| 752 | |
| 753 | lines: list[str] = [] |
| 754 | for path in md_files: |
| 755 | text = path.read_text(encoding="utf-8") |
| 756 | fm_dict = frontmatter.parse(text) |
| 757 | brief = _resolve_description(fm_dict) |
| 758 | etype = str(fm_dict.get("type") or "").strip().lower() or "other" |
| 759 | n_sources = len(fm_dict["sources"]) if isinstance(fm_dict.get("sources"), list) else 0 |
| 760 | if not brief: |
| 761 | parts = frontmatter.split(text) |
| 762 | body = parts[1] if parts is not None else text |
| 763 | brief = body.strip().replace("\n", " ")[:150] |
| 764 | suffix = f" — {brief}" if brief else "" |
| 765 | lines.append(f"- {path.stem} ({etype}, {n_sources} sources){suffix}") |
| 766 | |
| 767 | return "\n".join(lines) or "(none yet)" |
| 768 | |
| 769 | |
| 770 | def _iter_h2_headings(lines: list[str]) -> list[tuple[int, str]]: |