agentleFS
dan-blancharddan-blanchard/mtg-skills/lgs-search/SKILL.md

lgs-search

Skill28 starsChanged 2 months ago0BSDView on GitHub

Search The Gathering Place + Atomic Empire (LGS) and TCGPlayer + Mana Pool (online) for an MTG card list, allocate to minimize total cost across at most three carts, and hand off pre-loaded headed browser windows for checkout.

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 5 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    NEVER report a price the CLI did not return: Every price in the summary must come from a real Playwright search/cart result.

    line 14
  2. Very specific:

    Use run_in_background=True and tail the output file if you need to report progress.

    line 38
  3. Distinctive:

    If you skip the explicit logins, the orchestrator will pop a headed window the first time it detects "not logged in" — slightly more …

    line 62
  4. Distinctive:

    If neither LGS has it OR the online price proxy is much cheaper (default: >20% OR >$2), the card spills to the online bucket.

    line 118
  5. Very specific:

    Don't pass --bulk-data unless you need a specific path.

    line 143
  6. Distinctive:

    If you see this error, the user must clear the polluted cart before re-running.

    line 170
  7. Very specific:

    Before any cart is touched, every target store's cart is inspected.

    line 183
  8. Very specific:

    If any cart is non-empty, the run aborts with a clear message naming the polluted store(s).

    line 184
  9. Distinctive:

    If you see it, the store's results are incomplete: say so in the report rather than treating its misses as real stock-outs.

    line 237

≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

LGS Search

Source an MTG card list across the two local game stores (The Gathering Place, Atomic Empire) and the two big online catalogs (TCGPlayer, Mana Pool), allocating to minimize total cost. The user ends up checking out at most three carts: TGP, AE, and one of (TCGPlayer | Mana Pool), whichever is cheaper for the spillover.

The Iron Rule

NEVER report a price the CLI did not return. Every price in the summary must come from a real Playwright search/cart result. Scryfall USD is used internally as a proxy for the LGS-vs-online spill check — it does NOT appear in the report. Out-of-stock and unfindable lists must reflect actual page outcomes, not training-data guesses.

Running the orchestrator

The orchestrator is a normal long-running CLI that opens headed Chromium windows during Phase 5 / Phase 7. It is safe to launch from a Bash subprocess; the user closes the headed windows in the OS to advance, and the subprocess sees the close events without any terminal interaction. Do NOT reflexively ask the user to invoke with the ! prefix — that's only needed when something reads from stdin, and with --yes skipping the initial confirmation plus already-saved logins plus clean carts, no input() prompts fire.

Recommended invocation for an agent:

uv run --directory <skill-install-dir> lgs-search \
    --input <list> --output-dir <dir> --yes

Use run_in_background=True and tail the output file if you need to report progress. Only fall back to suggesting ! lgs-search ... when you have a specific reason to expect a stdin prompt (login fallback firing on an unlogged-in store, or a cart-pollution prompt without --clear-existing-carts).

Setup (First Run)

uv sync --directory <skill-install-dir>
uv run --directory <skill-install-dir> playwright install chromium

# One-time login per store (saves to ~/.cache/mtg-skills/lgs-profiles/<store>/):
lgs-search login --store tgp
lgs-search login --store atomic_empire
lgs-search login --store tcgplayer
lgs-search login --store manapool

A saved profile holds that store's live session cookies, which work like the password until the session expires. The profile dirs are owner-only (0700). To forget the sessions after shopping, run lgs-search logout (every store) or lgs-search logout --store <store>.

If you skip the explicit logins, the orchestrator will pop a headed window the first time it detects "not logged in" — slightly more disruptive but functionally equivalent. TGP needs this every run: its signed-in cookie is session-only, so a login --store tgp window signs in only until it closes. At cart build the run opens TGP's sign-in page in the cart window and watches it (await_login, up to 10 minutes, no stdin), so tell the user to sign in there when the window appears.

Workflow

Phase 1 — Resolve input

Accept either a parsed-deck JSON or a plain text list (one card per line, optional Nx prefix). Mainboard + sideboard are summed. Basic lands (Plains, Island, Swamp, Mountain, Forest, Wastes) are filtered out by default and surfaced in the summary; pass --include-basics to override. Snow basics (Snow-Covered Plains etc.) are NOT skipped.

Exact printings. Pass --exact-printings when the user wants the printings their list names. A line's (set) number and *F* / *E* then pin that printing; Moxfield's lowercase codes and trailing category tags ([Sac Outlet]) are read too. Two printings of one card stay two lines. A store's copy counts when it is that printing, or another printing with the same art and style (same illustration, frame, border, frame effects, stamps and foil treatment; The List's THB-9 Daxos is Theros Beyond Death's 9). TGP gives set and number, so its matches are exact; Atomic Empire gives no number, so its matches are by set and variant labels ("Showcase"), and a set with several look-alike printings (most tokens) is rejected rather than guessed. Mana Pool gets qty name [SET] number *F* lines with its Exact tab selected, and the summary lists the lines its Exact tab can't fill. TCGPlayer's Mass Entry can't take a collector number, so it is skipped whenever any line is pinned. Without the flag, printings are ignored and the cheapest copy of each card is bought.

Phase 2 — LGS sweep

Both LGS are queried for every card name once (a card's pinned printings share the search). Results are kept as the cheapest listing matching the user's preferences (condition, foil, preferred set, and a pinned printing). A failed search counts as "not in stock" at that store; the first failure per store is printed, so a broken adapter shows.

TGP is searched through the LGS Companion API its search page reads (lgsc-search.lgs-companion.com), one listing per in-stock English condition with its own price and stock. It allows about 15 searches a minute and answers 429 with Retry-After: 60; the adapter waits and retries, so a long list takes a few minutes at TGP. TGP prices a row it won't sell at $9,999.00; those rows are dropped.

Phase 3 — Allocate

For each card:

  • If neither LGS has it OR the online price proxy is much cheaper (default: >20% OR >$2), the card spills to the online bucket.
  • Otherwise: cheapest LGS wins. If both LGS prices are within $1 or 10%, the card is consolidated to the LGS with the higher running cart total to minimize trips.
  • Quantity > 1: split across stores when no single store can fill the full quantity. Residual goes online.

The online price proxy is the cheapest non-foil non-digital USD across all printings of each card (from the MTGJSON card data, through the shared card pool, so a two-faced card named by its front face — "Brazen Borrower" — is priced too), not the default printing's USD. Default-printing prices often miss cheap reprints (e.g. Beast Within's default has no usd, but its cheap reprint is $0.50; Kessig Wolf Run's default is ~$15, cheapest reprint $0.30). For a pinned printing the proxy is the cheapest printing that counts as it, in its finish. Without bulk data the proxy is 0.0 — the spill check goes silent and every in-stock LGS listing wins, even when MP/TCG would be 5-30x cheaper.

The orchestrator auto-detects the MTGJSON card data that download-mtgjson writes (under $MTG_SKILLS_CACHE_DIR or ~/.cache/mtg-skills/), the same lookup every other tool uses. When nothing is found, it prints a loud warning explaining the silent-no-spill failure mode and pointing at download-mtgjson. Don't pass --bulk-data unless you need a specific path.

Phase 4 — Online optimize

The spillover list is submitted to TCGPlayer Mass Entry and Mana Pool's /add-deck. Each site's optimizer runs (consolidates sellers, computes shipping). The cart with the lower items + shipping total is selected. Tax is computed at checkout.

Mana Pool's optimizer keeps refining for a while (22 s for a 113-item cart), and its three options settle at different times. The adapter waits until the button stops reading "Optimizing" (the spinner), not for one total to hold still. It then takes Balanced unless Lowest price saves at least $5 AND 10% of Balanced's total (manapool.BALANCED_MIN_SAVINGS_USD / _PCT), since a few dollars aren't worth a cart split into twice the packages. The summary shows the option taken with its package count beside the others.

Both Marketplaces' bulk-submit endpoints append to the existing cart rather than replacing it, so the optimizer's totals reflect the WHOLE cart (pre-existing items + new submission). The adapter runs a get_existing_cart pre-flight at the top of bulk_submit_and_optimize and raises CartNotEmptyError when non-empty; the orchestrator catches this in optimize_marketplace's per-store loop, prints a clear "[store] cart already has N items" error, and continues with whichever Marketplace still works.

If you see this error, the user must clear the polluted cart before re-running. MP's UI "Clear cart" button is broken in MP itself (verified: the click fires Sentry errors and a no-op metadata-sync RPC), so the user clears MP manually in the headed handoff window. TGP's clear_cart works programmatically and is invoked when --clear-existing-carts is passed.

Phase 5 — Confirmation gate + cart build

The full markdown allocation is printed; default-N prompt asks whether to proceed. Pass --yes to skip the prompt; pass --dry-run to stop after generating the allocation without touching any cart.

Before any cart is touched, every target store's cart is inspected. If any cart is non-empty, the run aborts with a clear message naming the polluted store(s); pass --clear-existing-carts to empty them automatically before adding.

Phase 6 — Unfindable + relaxed retry

Cards that no store can source after Phase 5 are listed. The user is prompted to retry with relaxed constraints (allow MP/HP, allow foil, drop preferred-set bias). --retry-relaxed automates one such retry.

Phase 7 — Handoff

For each store with a non-empty cart, a headed Chromium window is launched on the cart URL using the store's persistent profile. The user reviews and checks out manually. Pass --no-handoff to skip.

--collection subtracts what you own by the paper ownership rule (ADR-0058): basic lands count as owned, so they drop off the list — unless you pass --include-basics, which keeps them on the list to buy whatever the collection holds.

Flag reference

lgs-search \
  --input <deck.json | cards.txt> \
  [--collection <collection.json>]
  [--bulk-data <default-cards.json>]
  [--condition {nm,lp,mp,hp,any}]   # default: lp (worst condition allowed)
  [--allow-foil]
  [--prefer-set <SET>]
  [--exact-printings]
  [--lgs-online-threshold-pct 20]
  [--lgs-online-threshold-usd 2.00]
  [--consolidate-threshold-pct 10]
  [--consolidate-threshold-usd 1.00]
  [--no-handoff]
  [--dry-run]
  [--retry-relaxed]
  [--clear-existing-carts]
  [--include-basics]
  [--yes]
  [--search-timeout-seconds 20]
  [--cart-timeout-seconds 30]
  [--max-retries 3]
  [--output-dir <dir>]

Failure modes

  • Site selectors changed. Adapter raises StoreSelectorError with the failed selector and the URL where it was missed. The sweep prints the first such error per store ([tgp] search failed (...)) and counts that store out of stock for every card whose search failed. If you see it, the store's results are incomplete: say so in the report rather than treating its misses as real stock-outs. (TGP's move to a client-side search page, 2026-11, broke every TGP search silently before this was printed.)
  • Login expired. Detected per-store via is_logged_in. At cart build the store's window opens on its sign-in page and the run waits until the page shows the user signed in (up to 10 minutes; leave the window open — it becomes the cart window).
  • Marketplace cart pollution. bulk_submit_and_optimize raises CartNotEmptyError if the Marketplace's cart already has items (Phase 4 would mix the user's pre-existing items into the optimizer comparison). The orchestrator skips that Marketplace and continues with the other; user clears manually before re-running.
  • TCGPlayer captcha. TCG's anti-bot detects Playwright's persistent_context and blocks login (verified). The per-store-failure-tolerant optimize_marketplace skips TCG with a logged message and lets MP win by default. Don't waste time trying to log in to TCG headed — the captcha can't be cleared.
  • MP "Clear cart" no-op. MP's own SvelteKit handler for the Clear cart button throws (Sentry-reported) and the cart never changes. --clear-existing-carts falls back to a manual prompt for MP. The user clears in the headed cart window and presses Enter.
  • Cart line-item caps. Some stores cap line items per cart. If hit, the adapter partial-fills and reports a residual; the residual is logged in the sidecar and surfaced in the summary.
  • HTTP 429 / rate limit. Respected via Retry-After or 30s default; 3 consecutive 429s on one store skips that store with a warning.
  • Cart-add failure during Phase 5. Fatal. Fix the underlying issue and re-run from scratch — there is no resume path. The sidecar at <output-dir>/lgs-cart-allocation.json is a write-only audit record of what happened, not a checkpoint.

Hand-back to deck-wizard / cube-wizard

This skill never modifies decks. Unfindable cards are surfaced in the markdown summary — the calling skill or the user decides whether to substitute. There is no automatic "swap in a similar card" path.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.