Build the normalized-form → canonical-target index used by :func:`strip_ghost_wikilinks`. Useful when calling ``strip_ghost_wikilinks`` repeatedly with the same ``known_targets`` (e.g. ``fix_broken_links`` scanning N wiki files, or ``_save_transcript`` stripping N assistant turns) —
(known_targets: set[str])
| 48 | |
| 49 | |
| 50 | def build_norm_index(known_targets: set[str]) -> dict[str, str]: |
| 51 | """Build the normalized-form → canonical-target index used by |
| 52 | :func:`strip_ghost_wikilinks`. |
| 53 | |
| 54 | Useful when calling ``strip_ghost_wikilinks`` repeatedly with the same |
| 55 | ``known_targets`` (e.g. ``fix_broken_links`` scanning N wiki files, or |
| 56 | ``_save_transcript`` stripping N assistant turns) — build the index |
| 57 | once and pass it via the ``norm_index`` parameter to avoid O(N·M) |
| 58 | redundant rebuilds. |
| 59 | """ |
| 60 | return {_normalize_target(t): t for t in known_targets} |
| 61 | |
| 62 | |
| 63 | def strip_ghost_wikilinks( |