Skip to content

Give each named valuable a phrase for a sentence - #356

Merged
mmacy merged 7 commits into
mainfrom
valuable-phrases
Nov 26, 2026
Merged

mmacy merged 7 commits into
mainfrom
valuable-phrases

Conversation

@mmacy

@mmacy mmacy commented Nov 26, 2026

Copy link
Copy Markdown
Owner

Fixes #354 and #355.

The problem

PlayerView.valuable_names gives a named gem's or piece of jewellery's name as its author wrote it for a list, and the 2.9.0 docs told a client to use it as written in a sentence. That reads "Wren takes Silver altar candlestick." A client can't tell a common noun from a proper name, so it can't choose the article or the case.

The change

  • ValuableSpec.phrase and ValuableInstance.phrase are new optional fields: what to call the piece in the middle of a sentence, with its article and its case, such as "the abbot's seal ring". The session copies the phrase from the spec to the piece where it copies the name.
  • PlayerView.valuable_phrases has exactly the keys of valuable_names. Each value is the piece's phrase, or one made from its name when the phrase is empty or only whitespace. A name whose first word is "the", "a", or "an" keeps that word in lowercase. Any other name gets its first character in lowercase and "an" or "a" in front, by its first letter, and an accented vowel counts as a vowel.
  • A name of whitespace alone is no name of its own (A valuable whose name is only whitespace counts as having a name of its own #355). The view also trims the whitespace around a name and a phrase, in both maps and in a pile's items. The stored pieces keep what the author wrote.
  • The docstrings and guides now send a list to valuable_names and a sentence to valuable_phrases. The authoring guide says when to set phrase.

Everything is additive. A 2.9.0 save loads and gets a phrase for every named piece, and a PlayerView that 2.9.0 built validates with valuable_phrases empty. No RNG stream draws differently, and SCHEMA_VERSION doesn't change. tests/goldens/phase5_hoards.json gains "phrase": "" on each valuable, because a hoard dumps whole ValuableInstance models.

How it was checked

  • tests/test_view_valuable_phrases.py, 43 tests, written before the implementation by a different agent, with two fixtures written by a scratch copy of v2.9.0.
  • An independent review replayed 150 fuzzed command sequences (1,677 steps) against 2.9.0 and found no difference except phrase and valuable_phrases. That replay ran before the trimming change, which changes valuable_names and a pile's items only for a name with whitespace around it.
  • The gate: ruff format --check, ruff check, pyright, pytest (7,772 passed, 156 skipped), mkdocs build --strict, and tools.srd_compile with no diff under src/osrlib/data.

https://claude.ai/code/session_01V7Ertq3gKJ46oFQD6635f3

The stubs are `ValuableSpec.phrase` and `ValuableInstance.phrase`, both defaulting to the empty string, and
`PlayerView.valuable_phrases`, defaulting to an empty map, each with its final docstring. The spec's player view
paragraph names the new map. The tests in tests/test_view_valuable_phrases.py are marked xfail with the reason
"chunk: valuable-phrases", except three guards that already pass: an adventure document keeps a phrase, a piece the
party can't see has no phrase in the view, and a PlayerView that osrlib 2.9.0 built validates with no phrases.

tests/goldens/phase5_hoards.json gains an empty `phrase` key on every generated valuable, because a hoard dumps its
ValuableInstance models whole. Nothing else in it changes. The two fixtures under tests/saves/ were written by a
scratch copy of v2.9.0 from the test module's own builder.

Claude-Session: https://claude.ai/code/session_01V7Ertq3gKJ46oFQD6635f3
A piece whose name is only whitespace is a key in valuable_names and shows a blank
entry in a pile. The test pins that it has no name of its own, in both maps and in
the pile's items.

Claude-Session: https://claude.ai/code/session_01V7Ertq3gKJ46oFQD6635f3
PlayerView.valuable_phrases has the same keys as valuable_names and gives each piece's phrase with
its article and case, so a remote front end can word "Wren takes a silver altar candlestick." from
the view alone. The phrase is the piece's own `phrase` when it isn't empty or only whitespace, and
otherwise osrlib makes it from the name: a first word of "the", "a", or "an" is lowered, and any
other name has its first letter lowered and "an" or "a" in front. Taking a placed cache copies
ValuableSpec.phrase to the ValuableInstance as it copies `name`, so saves round-trip it and a 2.9.0
save, whose pieces have no phrase, gets made phrases.

A piece whose name is only whitespace now has no name of its own (#355): it is a key in neither
map, and a pile's `items` show its kind instead of the blank string.

The docstrings of PileItemView, PlayerView.item_names, and PlayerView.valuable_names send a list to
valuable_names and a sentence to valuable_phrases. The authoring guide gains a section on naming a
valuable and when to set `phrase`, and the views and FastAPI guides name the new map.

No golden file changes.

Claude-Session: https://claude.ai/code/session_01V7Ertq3gKJ46oFQD6635f3
PileView.items is a tuple, so the comparison with a list could never pass.

Claude-Session: https://claude.ai/code/session_01V7Ertq3gKJ46oFQD6635f3
The view trims a name and a phrase and judges a name of its own on the trimmed
name, an accented vowel takes "an", and the docstrings say "first character" and
name the kind each rolled name belongs to. The guide and the changelog say when to
set a phrase without listing phrases that read wrong.

Claude-Session: https://claude.ai/code/session_01V7Ertq3gKJ46oFQD6635f3
…el "an"

The amended contract has the view trim the whitespace around a valuable's name and phrase: the
values of valuable_names and valuable_phrases and a pile's items show the trimmed text, and a piece
has a name of its own when its trimmed name is neither empty nor its kind's rolled name, so " Gem "
is a rolled gem's lookalike. The stored pieces keep what the author wrote.

_with_article reads the first character's base letter after Unicode decomposition, so "Émeraude"
and "Öl-lamp" take "an" and "Çintamani" takes "a". Its other callers pass built-in ASCII names,
whose articles don't change, and no golden file changes.

The authoring guide no longer says valuable_names gives the name as you wrote it.

Claude-Session: https://claude.ai/code/session_01V7Ertq3gKJ46oFQD6635f3
@mmacy
mmacy merged commit 1f862be into main Nov 26, 2026
5 checks passed
@mmacy
mmacy deleted the valuable-phrases branch November 26, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

valuable_names can't be used mid-sentence, because common nouns and proper names look alike

1 participant