From bb1e391d4919c4ed4131d86ed6c4e1d29454623c Mon Sep 17 00:00:00 2001 From: NoHudd <86909140+NoHudd@users.noreply.github.com> Date: Tue, 8 Sep 2026 07:39:12 -0500 Subject: [PATCH 001/131] feat(commands): "Did you mean" hints on not-found errors A typo like `take segfault_sheld` used to dead-end at "Cannot find segfault_sheld in this directory." with no clue whether the mechanic or the spelling failed. Now every not-found path (take, cat, examine, talk, drop, equip, cd) appends one line: the close match via difflib, or the list of what is actually here. cd hints only discovered exits so hidden rooms stay hidden. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01XZzvukbvLcLhqtaJMd6KxS --- src/commands/hints.py | 64 ++++++++++++++++++++++++ src/commands/items.py | 58 ++++++++++++++++------ src/commands/navigation.py | 21 +++++++- tests/test_not_found_hints.py | 92 +++++++++++++++++++++++++++++++++++ 4 files changed, 219 insertions(+), 16 deletions(-) create mode 100644 src/commands/hints.py create mode 100644 tests/test_not_found_hints.py diff --git a/src/commands/hints.py b/src/commands/hints.py new file mode 100644 index 0000000..5da177d --- /dev/null +++ b/src/commands/hints.py @@ -0,0 +1,64 @@ +"""Follow-up lines for not-found errors. + +A bare "Cannot find X" leaves the player guessing whether the mechanic failed +or their spelling did. These helpers add one line after the error: the close +match they probably meant, or, failing that, what is actually available. +""" +from __future__ import annotations + +import difflib +from collections.abc import Iterable +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from src.command_handler import CommandHandler + +_CUTOFF = 0.6 + + +def not_found_hint(typed: str, candidates: Iterable[str], *, label: str) -> str: + """One markup line to show after a not-found error, or "" if nothing to say. + + Close match (case-insensitive) -> "Did you mean ?" + Otherwise -> "