Repository navigation
Add owner-only /coachadmin control surface - #47
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A private, owner-only
/coachadmincommand for controlling the bot — the public/coachcommand 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 (mirrorstts/voices.ts) seeded from config, holding the read-live settings;log,engine,roster, andindexread it in place ofconfig.LlmCoach/VoiceCoachgained live setters+getters for the construction-captured settings (model/effort/volume), all read fresh per call; public/coach statusnow shows the live LLM model.src/discord/admin-settings.ts(new) — the safe-allowlist parse/validate/apply registry, composed inindex.tswherellm/voicelive.LinkStoregainedlist(),remove(),removeAllForDiscord().remove()repairs thebyDiscordreverse map (re-points to a surviving alt, or drops the entry). Constructor now takes an optional state-file path for testability.SessionStoregainedrecent(),clear(),deleteLast()(the atomic write was extracted into a sharedpersist()).TtsCachegainedstats()/clear();TtsChainexposescacheStats()/clearCache().RosterManager.feedsDetailed()exposes per-feed SteamID64s (the existingconnectedFeeds/quarantinedFeedsdeliberately hide them).Reviewer notes
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