Skip to content

feat(decks): rank owned-card upgrades by deck fit, not just legality (#294) - #348

Merged
untraceablez merged 1 commit into
mainfrom
feat/294-synergy-upgrades
Aug 21, 2026
Merged

feat(decks): rank owned-card upgrades by deck fit, not just legality (#294)#348
untraceablez merged 1 commit into
mainfrom
feat/294-synergy-upgrades

Conversation

@untraceablez

Copy link
Copy Markdown
Collaborator

Closes #294. One of the two remaining items in the Decks & EDH tooling milestone; #295 is the sibling and reuses this scoring.

The problem

The heuristic suggester returned cards that were owned, in colour identity and Commander-legal, ranked by curve then price. Those rules make a pick allowed, not good — a generic in-colour mana rock could outrank a card that actually does what the deck is trying to do.

What changes

Candidates are now scored against the deck's plan first, with curve and price kept as tie-breakers. A deck with no detectable theme ranks exactly as it did before — only decks that have a plan see any difference.

Two signals, both offline and deterministic (no LLM, no network, no new data source):

  • Themes — recurring keywords plus rules-text patterns (+1/+1 counters, tokens, sacrifice, lifegain, spellslinger, mill, graveyard recursion).
  • Tribes — creature types the deck cares about, derived from the deck itself rather than from a hardcoded list: types the commander's rules text names, or that enough of the deck's creatures already share. Magic has hundreds of creature types and gains more every set, so a literal list would be wrong within a year; this stays correct for types invented after it was written. A tribal hit outweighs a text match, because it's the deck's whole plan rather than one mode of a card.

Whatever matched is shown on the pick — "matches your tokens, elf". An unexplained recommendation is one the reader has no way to disagree with, which is really the complaint behind this issue.

Shared plumbing, not a second copy

Theme detection moved out of llm.py into a new src/deck_synergy.py. It had to be shared: the deliberately-offline suggester can't import the LLM module to reuse it, and a second copy would drift. This repo has already paid for that once — two card-name resolvers disagreed until DFCs matched from a decklist but not from a CSV (#338). #295 asks for the same plumbing as its pre-filter, so it's there waiting.

Two things found while building it

  • The plural of Elf is Elves. My first pass matched elfs?, which silently found nothing for Elf, Wolf, Dwarf and Ally — precisely the tribes people build decks around. Now only the irregulars real creature types actually use are handled, and an unknown one degrades to a missed signal rather than a wrong one.
  • Subtypes are read from creature type lines only, so an Aura-heavy deck doesn't come out as "Aura tribal".

Deliberately not included

#294 lists a game_changer "staple-ness" boost as optional. I left it out on purpose: those cards raise a deck's bracket (src/brackets.py), so silently floating them to the top of an upgrades list would change something about the deck that the suggester never mentions. That's worth doing as an explicit, labelled signal — "strong, but raises your bracket" — rather than a hidden ranking nudge, and it's a decision worth making on its own rather than smuggling in here.

Verification

  • 1274 passed, 100% coverage, 0 missed lines (16 new tests). ruff and mkdocs --strict clean. No migration.
  • The behaviour tests are the point: a synergistic Ramp card outranks a generic one; synergy beats a cheaper, lower-curve generic; a themeless deck's ordering is unchanged; sideboard cards don't shape the profile.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LxrePqFWyzQTcWaroSk4sH

…294)

The heuristic suggester returned cards that were owned, in colour identity and Commander-legal,
ranked by curve then price. That guarantees a *legal* pick, not a *good* one: a generic in-colour
rock could outrank a card that actually does what the deck is trying to do.

Candidates are now scored against the deck's plan first, with curve and price kept as tie-breakers —
so a deck with no detectable theme ranks exactly as it did before, and only decks that *have* a plan
see any change.

Two signals, both offline and deterministic:

* **Themes** — recurring keywords plus rules-text patterns (+1/+1 counters, tokens, sacrifice,
  lifegain, spellslinger, mill, graveyard recursion).
* **Tribes** — creature types the deck cares about, derived **from the deck** rather than a hardcoded
  list of creature types: types the commander's text names, or that enough of the deck's creatures
  already share. Magic has hundreds of types and gains more every set, so a literal list would be
  wrong within a year; this stays correct for types invented after it was written. A tribal hit is
  weighted above a text match because it's the deck's whole plan rather than one mode of a card.

Whatever matched is surfaced on the pick ("matches your tokens, elf"). An unexplained recommendation
is one the reader has no way to disagree with, which is the actual complaint behind this issue.

Theme detection moves out of `llm.py` into a new `src/deck_synergy.py`. It had to be shared: the
offline suggester can't import the LLM module to reuse it, and a second copy would drift — this repo
has already paid for exactly that, with two card-name resolvers that disagreed until DFCs matched
from a decklist but not from a CSV (#338). #295 reuses the same scoring as its pre-filter.

Two things found while building it:

* **The plural of Elf is Elves.** A naive `s?` match silently found nothing for Elf, Wolf, Dwarf and
  Ally — precisely the tribes people build around. Only the irregulars real creature types use are
  handled; an unknown one degrades to a missed signal rather than a wrong one.
* Subtypes are read from **creature** type lines only, so an Aura-heavy deck isn't "Aura tribal".

Deliberately not included: a `game_changer` quality boost, which #294 lists as optional. Those cards
raise a deck's bracket (`src/brackets.py`), so silently floating them to the top of an "upgrades"
list would change something about the deck the suggester never mentions. Worth doing as an explicit,
labelled signal rather than a hidden ranking nudge.

16 new tests; suite 1274 passing at 100% coverage.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LxrePqFWyzQTcWaroSk4sH
@untraceablez
untraceablez merged commit 4c0f1b1 into main Aug 21, 2026
8 checks passed
@untraceablez
untraceablez deleted the feat/294-synergy-upgrades branch August 21, 2026 20: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.

Improve heuristic owned-card upgrade suggestions (synergy / deck-fit, not just legality)

1 participant