Skip to content

Add owner-only /coachadmin control surface - #47

Merged
PureXYZ merged 3 commits into
mainfrom
claude/pensive-goodall-5a69e3
Jun 14, 2026
Merged

PureXYZ merged 3 commits into
mainfrom
claude/pensive-goodall-5a69e3

Conversation

@PureXYZ

@PureXYZ PureXYZ commented Jun 14, 2026 •

Copy link
Copy Markdown
Owner

What

A private, owner-only /coachadmin command for controlling the bot — the public /coach command is unchanged (every member keeps the access they have today).

It's registered only to a private admin guild (a server with just you + the bot), so it's invisible in the public server's command picker — even to other admins (Discord has no native "show this command to one user" gate). Use is also hard-gated at runtime on interaction.user.id === COACH_OWNER_ID, keyed on the gateway-authenticated identity, never the self-asserted Steam link. All replies are ephemeral.

Both new env vars must be set to enable it; with either unset, nothing is registered and the surface is fully dormant — safe to deploy before you've set it up.

Subcommands

  • status — detailed readout: each feed's SteamID64 (hidden from the public status) cross-referenced to its linked Discord user, plus confirmed/quarantine reason and primary/authority tags. Lets you identify a misconfigured/griefer feed.
  • link list / set / remove — view all Steam↔Discord pairings; manually fix one (confirm-on-overwrite); remove one by SteamID64 or all of a user's accounts incl. alts (confirm-before-destroy). Each mutation notes that per-payload auto-capture will re-assert the cfg-baked id, so a manual fix is a stopgap.
  • settings / set <key> <value> — change settings on the fly: nickname, team-tactics, warmup-speech, squad-recap, debug, llm-model / llm-fast-model / llm-effort, volume. Session-scoped — everything resets to the env default on restart. Squad size and primary SteamID64 are deliberately excluded (env-only).
  • sessions list / delete-last / clear — inspect recent recorded matches (result/score/map/own K-D/age), drop just the most recent (e.g. a practice match that slipped the recording guards), or wipe the whole history. Destructive actions confirm first.
  • tts stats / prewarm / clear — show the audio-cache size, re-synthesize all cacheable lines in the background (fire-and-forget, skips already-cached), or empty the cache (confirm) — handy after editing lines/voices since the bot can't restart itself.

How

  • src/runtime-overrides.ts (new) — a session-scoped singleton (mirrors tts/voices.ts) seeded from config, holding the read-live settings; log, engine, roster, and index read it in place of config. LlmCoach/VoiceCoach gained live setters+getters for the construction-captured settings (model/effort/volume), all read fresh per call; public /coach status now shows the live LLM model.
  • src/discord/admin-settings.ts (new) — the safe-allowlist parse/validate/apply registry, composed in index.ts where llm/voice live.
  • LinkStore gained list(), remove(), removeAllForDiscord(). remove() repairs the byDiscord reverse map (re-points to a surviving alt, or drops the entry). Constructor now takes an optional state-file path for testability.
  • SessionStore gained recent(), clear(), deleteLast() (the atomic write was extracted into a shared persist()). TtsCache gained stats()/clear(); TtsChain exposes cacheStats()/clearCache().
  • RosterManager.feedsDetailed() exposes per-feed SteamID64s (the existing connectedFeeds/quarantinedFeeds deliberately hide them).
  • The boot-time command-registration cleanup now skips the admin guild, and the admin command is registered additively, so it survives every restart.

Reviewer notes

  • The highest-risk new code is LinkStore.remove()'s reverse-map repair for alt accounts (one Discord user → multiple SteamID64s). New sim scenarios cover it plus the SessionStore ops and persistence.
  • volume > 1 routes audio through ffmpeg (bundled on the droplet; would break audio on a local box without ffmpeg).
  • npm test (typecheck + sim) is green.

To activate

Create a private server, invite the bot, and set COACH_OWNER_ID (your user ID) + COACH_ADMIN_GUILD_ID (the server ID) in .env (local + droplet), then redeploy. Guild-scoped registration is instant.

🤖 Generated with Claude Code

PureXYZ and others added 3 commits June 14, 2026 15:52
A private control command, separate from the public /coach (which is
unchanged), for managing the bot. It's registered ONLY to a private admin
guild — so it's invisible in the public server, even to other admins — and is
hard-gated at runtime on interaction.user.id === COACH_OWNER_ID. Both new env
vars (COACH_OWNER_ID + COACH_ADMIN_GUILD_ID) must be set to enable it; with
either unset nothing is registered and the surface is fully dormant. All
replies are ephemeral.

Subcommands:
- status: detailed readout — each feed's SteamID64 (hidden from the public
  status) cross-referenced to its linked Discord user, with confirmed/quarantine
  reason and primary/authority tags.
- link list / set / remove: view all Steam<->Discord pairings; manually fix one
  (confirm-on-overwrite); remove one by SteamID64 or all of a user's accounts
  (incl. alts), with confirm-before-destroy. Every mutation notes that
  auto-capture will re-assert the cfg-baked id, so a manual fix is a stopgap.
- settings / set <key> <value>: change settings on the fly (nickname,
  team-tactics, warmup-speech, squad-recap, debug, llm model/fast-model/effort,
  volume). Session-scoped: everything resets to the env default on restart.
  Squad size and primary SteamID64 are deliberately excluded (env-only).

Implementation:
- New src/runtime-overrides.ts: a session-scoped singleton (mirrors tts/voices.ts)
  seeded from config, holding the read-live settings; consumers (log, engine,
  roster, index) read it instead of config. LlmCoach/VoiceCoach gained live
  setters+getters for the construction-captured settings (model/effort/volume),
  all read fresh per call. Public /coach status now reads the live LLM model.
- LinkStore gained list(), remove(), and removeAllForDiscord(); remove() repairs
  the byDiscord reverse map (re-points to a surviving alt or drops the entry).
  Its constructor now takes an optional state-file path for testability.
- RosterManager.feedsDetailed() exposes per-feed SteamID64s (the existing
  connectedFeeds/quarantinedFeeds deliberately hide them).
- The boot-time command-registration cleanup now skips the admin guild, and the
  admin command is registered additively, so it survives every restart.
- New sim scenario (16 checks) covers the link reverse-map repair, alt handling,
  and persistence. .env.example documents the new vars. typecheck + sim green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Phase 5 of the owner-only admin surface: two more subcommand groups on the
private /coachadmin command.

- sessions list | delete-last | clear: inspect recent recorded matches
  (result/score/map/own K-D/age), drop just the most recent (e.g. a practice
  match that slipped the recording guards), or wipe the whole history.
  Destructive actions confirm first.
- tts stats | prewarm | clear: show the audio-cache size, re-synthesize all
  cacheable lines in the background (fire-and-forget, skips already-cached),
  or empty the cache (confirm) — useful after editing lines/voices since the
  bot can't restart itself.

Store/chain additions: SessionStore gained recent()/clear()/deleteLast() (the
atomic write was extracted into a shared persist()); TtsCache gained
stats()/clear() (clear unlinks the blobs + rewrites the manifest); TtsChain
exposes cacheStats()/clearCache(). All wired into BotDeps from index.ts. New
sim scenario covers the SessionStore ops + persistence. typecheck + sim green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Addresses the bugs + cheap cosmetics from the xhigh code review.

Correctness:
- config: validate COACH_ADMIN_GUILD_ID with discordIdEnv (was unvalidated) — a
  typo'd guild id now fails loudly at startup instead of silently failing
  registration and locking the owner out behind an "enabled" boot log.
- bot: renderAdminStatus rendered the (unique) detailed feed table AFTER the
  base status then re-clamped to 1990, so a busy/griefed lobby truncated the
  table the command exists for. Render the detailed table first; also label it
  "(incl. idle feeds)" since it lists feeds within feedIdleMs while the base
  "Feeds:" line counts feedStaleMs.
- sessions delete-last was a TOCTOU: the confirm previewed the current newest
  match but the button popped whatever was newest at click time. Bind the
  confirm to the record's endedAt (epoch ms in the customId) and delete that
  exact record via new SessionStore.deleteByEndedAt().
- link remove <user>: the confirm interpolated every owned SteamID64 with no
  length clamp — a user with many alts could overflow Discord's 2000-char
  limit and throw. Cap at 20 + slice.
- links: record() on an owner change set the new byDiscord reverse pointer but
  never cleared the old owner's, breaking the one-steam64-per-id invariant that
  remove() maintains. Extract a shared repairReverse() and call it from both.
- tts: add a re-entrancy guard to TtsChain.prewarm so a repeated
  /coachadmin tts prewarm (or overlap with the startup prewarm) can't spawn
  concurrent loops that double up paid synth calls.

Cosmetic:
- session-store: log "Recorded match" only when the disk write succeeded
  (persist() now returns bool) — no more false success after a write failure.
- admin-settings: when the LLM is disabled, the llm-* settings rows no longer
  show as "changed this session" (env default now matches the placeholder).
- bot: /coachadmin tts prewarm reports the cache is disabled instead of a false
  "started" (matches tts clear).
- admin-settings: setting squad-recap while team-tactics is off now flags the
  coupling instead of claiming it's live.
- bot: warn at startup if COACH_ADMIN_GUILD_ID == DISCORD_GUILD_ID (would leak
  the owner command into the public server).

Sim: new coverage for deleteByEndedAt targeting and the record() owner-change
reverse-pointer repair. typecheck + sim green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@PureXYZ
PureXYZ merged commit 3af7afc into main Jun 14, 2026
1 check passed
@PureXYZ
PureXYZ deleted the claude/pensive-goodall-5a69e3 branch June 14, 2026 20:49
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.

1 participant