Parse every memory doc under ``memory_dir``, sorted by date then filename. Each record is the parsed frontmatter plus ``_path`` (the source file). Docs without recognisable frontmatter (foreign .md files, the LESSONS.md artifact) are skipped.
(memory_dir: Path)
| 131 | |
| 132 | |
| 133 | def load_memory_docs(memory_dir: Path) -> list[dict[str, Any]]: |
| 134 | """Parse every memory doc under ``memory_dir``, sorted by date then filename. |
| 135 | |
| 136 | Each record is the parsed frontmatter plus ``_path`` (the source file). Docs |
| 137 | without recognisable frontmatter (foreign .md files, the LESSONS.md artifact) |
| 138 | are skipped. |
| 139 | """ |
| 140 | memory_dir = Path(memory_dir) |
| 141 | if not memory_dir.exists(): |
| 142 | return [] |
| 143 | docs: list[dict[str, Any]] = [] |
| 144 | for path in sorted(memory_dir.glob("*.md")): |
| 145 | try: |
| 146 | text = path.read_text(encoding="utf-8") |
| 147 | except (OSError, UnicodeDecodeError): |
| 148 | continue |
| 149 | parsed = parse_memory_doc(text) |
| 150 | if parsed is None: |
| 151 | continue |
| 152 | parsed["_path"] = path.name |
| 153 | docs.append(parsed) |
| 154 | # Stable order: by (date, filename) so output is deterministic across runs. |
| 155 | docs.sort(key=lambda d: (d.get("date", ""), d["_path"])) |
| 156 | return docs |
| 157 | |
| 158 | |
| 159 | # --- graph / community lookup (optional) --------------------------------------- |