fix(tooling): PR #130 round 2 — stale strings, O(1) dedup, vestigial scope (#833)

- Fix "Gemma 2 GGUF" in user-facing error message (line 2073)
- Fix gemma2.gguf in docstring usage example (line 32)
- Fix O(N) _is_duplicate: pre-build lowercase shadow sets for O(1) lookup
- Expand vestigial note to enumerate full ~750-line dead island boundaries

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-18 00:43:11 +02:00
co-authored by Claude Opus 4.6
parent 8ba3a1d0a7
commit 160c3f1853
+20 -11
View File
@@ -28,8 +28,8 @@ Usage:
tooling/planet-gen/gemma_naming.py --limit 5 --verbose # smoke test
tooling/planet-gen/gemma_naming.py --mock # mock-stdio.sh (no model)
tooling/planet-gen/gemma_naming.py \\
--sr-voice /var/mnt/data/projects/settled-reach/main/server/sr-voice/target/release/sr-voice \\
--model /var/mnt/data/projects/settled-reach/main/server/models/gemma2.gguf
--sr-voice ~/Projects/settled-reach/binaries/sr-voice-tooling \\
--model ~/Projects/settled-reach/models/gemma-4.gguf
Exit codes:
0 pipeline completed (possibly with skipped bodies)
@@ -71,10 +71,16 @@ DB_PATH = REPO_ROOT / "server" / "data" / "systems.db"
WIKI_SYSTEMS = REPO_ROOT / "wiki" / "star-systems"
BLOCKLIST_PATH = TOOLING_DIR / "earth_blocklist.txt"
# NOTE: --dump-prompts and name_feature() are vestigial from the Gemma 2
# single-name pipeline. The live path uses _batch_fill() →
# name_features_batch() from naming_core.py. The old code is retained
# for reference but not called. TODO(#833): remove in a cleanup pass.
# NOTE: The following are vestigial from the Gemma 2 single-name pipeline.
# The live path uses _batch_fill() → name_features_batch() from naming_core.
# TODO(#833): remove in a cleanup pass. Full dead-code island (~750 lines):
# - _CAPTURE_FILE, --dump-prompts argparse (here + main())
# - _build_prompt() and its few-shot example pools (~lines 500-929)
# - post_process(), is_placeholder(), _PLACEHOLDER_TOKENS, _LABEL_PREFIX,
# _MD_BOLD, _MD_UNDER (~lines 1040-1100)
# - is_blocked(), load_blocklist() (~lines 1105-1140)
# - fallback_name(), _FALLBACK_STEMS, _FALLBACK_SUFFIXES (~lines 1145-1205)
# - name_feature() with its retry loop and _is_duplicate (~lines 1530-1655)
_CAPTURE_FILE = None # vestigial — see note above
# Default binary + model paths. The sr-voice binary is platform-specific
@@ -1596,16 +1602,19 @@ def name_feature(
body_used.add(placeholder)
return placeholder
# Pre-build lowercase shadow sets for O(1) dedup checks
used_lower = {n.lower() for n in used}
body_used_lower = {n.lower() for n in body_used}
def _is_duplicate(candidate: str) -> bool:
lc = candidate.lower()
return (
lc in (n.lower() for n in used)
or lc in (n.lower() for n in body_used)
)
return lc in used_lower or lc in body_used_lower
def _commit_name(final: str) -> None:
used.add(final)
used_lower.add(final.lower())
body_used.add(final)
body_used_lower.add(final.lower())
rejections: dict[str, int] = {"empty": 0, "placeholder": 0, "blocklist": 0,
"dedup": 0, "error": 0}
@@ -2070,7 +2079,7 @@ def main():
if model_path and not model_path.exists():
print(
f"error: model not found at {model_path}\n"
"Either download the Gemma 2 GGUF or run with --mock.",
"Either download the model GGUF or run with --mock.",
file=sys.stderr,
)
sys.exit(1)