Cross-repo audit + a new toolkit repo
Cross-repo audit + a new toolkit repo β Aug 18
TL;DR
Fanned out 5 subagents across all 24 repos in ~/code/ to find duplicated code and cool ideas worth stealing. Built a new shared repo, xpoes123/toolkit, that extracts four proven pieces: sage's error-handling kit, SharpLab's odds math, the hash-seeded avatar trick from nsba-cardai, and a VPS deploy script + shared design system. Nothing in sage/stavid/SharpLab/nsba-markets was touched β v1 is standalone, migration is a deliberate next step. A second research pass came back with 7 ranked ideas for what to build next; the strongest one wires arxiv-scrape's nightly-agent pattern into nsba-markets' strategy builder.
What I was asked to do
Look across all of David's repos for things worth abstracting into a shared toolkit, and for cool ideas/engineering practices worth replicating elsewhere or writing into memory/CLAUDE.md β specifically flagged nsba-markets' card avatar generation and the general Discord-bot patterns as promising.
The audit
Five agents covered: the Discord bots (sage, stavid, LeBot, nsba-results-bot), the NSBA/prediction-market family (nsba, nsba-markets, nsba-cardai, sharp-nba), the sports/quant repos (SharpLab, nba-modeling, poverty-football), the web apps (scibowl-org, david-share, davidJ, finance), and the smaller/misc projects (party, pokemon-cards, games, arxiv-scrape, the vigil-* worktrees).
The standout: hash-seeded avatar generation
nsba-cardai's CuteAvatar.tsx generates a unique, good-looking mascot for every player card with zero image files, zero AI API calls, zero server round-trip:
hash32(name)β an FNV-1a hash of the entity's name, so the seed is stable forever.- That seed drives a tiny inline xorshift32 PRNG.
- The PRNG picks indices into small hand-authored trait arrays β 8 color palettes, 4 body shapes, 6 eyes, 6 mouths, 5 accessories.
- Renders as one inline
. A pointer-reactive CSS layer (--px/--pycustom properties) adds a cursor-tilt "holo foil" effect on top, no canvas/WebGL.
Same name always produces the same avatar, computed in microseconds, no storage or CDN needed. This is now a standalone module in the toolkit (see below) so any other bot β Discord avatars, Stavid's habit-tracker mascots, a PokΓ©mon-cards "trainer" badge β can reuse the exact mechanism with its own art.
Real duplication found
| Pattern | Duplicated in | Now consolidated? |
|---|---|---|
| Odds/probability math (Americanβdecimalβprob, de-vig, Kelly) | SharpLab, nba-modeling (Γ2), nsba, sharp-nba | Yes β \1 |
| Discord error handling (sanitize + dedupe-by-fingerprint) | sage has it, stavid has none | Yes β \1 |
| Hash-seeded avatar mechanism | nsba-cardai only, but reusable anywhere | Yes β \1 + \1 |
| Tokyo Night CSS variables | finance + david-share, copy-pasted hex values | Yes β \1 |
| git-pull-deploy pattern | david-share has it, finance has no deploy script at all | Yes β \1 |
| LMSR market math | \1 vs \1, ported verbatim | Not yet β flagged in \1 |
| Config loading | pydantic-settings in some repos, raw \1 in others | Not yet β flagged as drift to fix opportunistically |
Also flagged: nsba-cardai turned out to be a stale full fork of nsba-markets's backend, not a distinct project β bug fixes there won't propagate. fantasy-football and pokemon-masterset are empty, candidates to archive.
What I built: `xpoes123/toolkit`
A new private repo at ~/code/toolkit, pip-installable, with an assert-based self-check in every module (python3 djtoolkit/oddsmath.py etc β no test framework needed):
djtoolkit/discord_kit.pyβsanitize_error/command_error_handler(never leak a raw traceback to Discord),load_all_cogs(glob-load cogs, log-not-crash on a bad one),ErrorDeduper(fingerprint exceptions by type+file+function so repeats don't re-alert).djtoolkit/oddsmath.pyβ the full odds-conversion toolkit from SharpLab (the most complete of three independent copies), plus akelly_fractionhelper.djtoolkit/avatar.py+web/avatar.tsβ the CuteAvatar mechanism, Python and TS versions kept in lockstep (verified they produce identical output from the same seed).deploy/git-pull-deploy.shβ generalized VPS-side deploy script; fails loud instead of force-overwriting if the pull isn't a clean fast-forward.web/tokyo-night.css+ a documented design-system rule: personal single-user tools (finance, david-share) get Tokyo Night; public-facing products (scibowl-org, davidJ) keep their own branding. Written into~/code/CLAUDE.md.
Deliberately not done: wiring any existing repo to actually import from djtoolkit yet. sage, stavid, SharpLab, nba-modeling, and nsba-markets all keep running their current local copies unchanged β several are live production systems (real Discord users, real trades), so that migration happens one repo at a time, on request.
What to build next β a ranked shortlist
A second research pass (informed by the audit) came back with 7 ideas, ranked. The full report is worth reading end to end, but the top 3:
- A nightly "agent tournament" for nsba-markets. arxiv-scrape already proved a headless-Claude pattern (ideate β build β judge β publish). Point that same harness at nsba-markets' strategy-builder DSL instead of arXiv papers: agents write competing trading strategies overnight, backtest them against real market data, and the judge promotes a winner to paper trading. Wires together three systems already built into something none of them could produce alone.
- A public "model vs. market" dashboard for nba-modeling. The RAPM+Elo modeling work is serious and currently completely invisible β no output beyond notebooks and Windows Task Scheduler batch files. Vigil already has the right visual language (fair value vs. market line); reuse it, publish through david-share.
- A tiny standalone "seed β creature" demo page for the new avatar module, to prove the extraction was worth it by getting the same trick into 2-3 unrelated bots in a weekend.
(Full list of 7, including a play-money LMSR market inside stavid for apartment-life predictions, and durable Temporal timers for sage's reminders, is in the session β ask if you want the complete writeup.)
Recommendations, in order
- Skim
toolkit/README.mdand the self-checks; nothing here is live yet so there's no urgency, but it's ready to wire in whenever. - Decide whether to migrate stavid onto
discord_kit's error handling first β it's the highest-value, lowest-risk integration (stavid currently has none). - Pick one of the 7 "build next" ideas if any of them sound fun β happy to scope any of them into a real plan.