feature_toggles
Per-channel feature toggles stored in Redis.
Allows authorised users to disable the NCM neurotransmitter subsystem
(cadence post-processing + NCM tools like inject_ncm) or the RAG
subsystem on a per-channel basis via !emotions on/off and
!rag on/off.
Full NCM disable (inhale, exhale, Golden Goddess reflex, emotion tools, cadence) is controlled by:
ncm_fully_disabled_channels(platform:channel_idstrings, default includes Aesir-Hall), and/orRedis key
stargazer:toggle:ncm:{channel_key}(same pattern as other toggles; set viaSET/DELor a future admin command).
NOTE: !emotions off does NOT affect the Sigma Limbic Recursion Core.
The limbic inhale (context injection) and exhale (emotional feedback loop)
always run. Star always knows her emotions. The toggle only disables
the surface layer: cadence text degradation and tool access to NCM.
Use the ncm toggle or config list when the entire NCM stack must be off.
Redis key scheme
stargazer:toggle:{feature}:{channel_key}
where feature is "emotions", "rag", or "ncm" and channel_key
is "{platform}:{channel_id}".
For Discord, discord and discord-self share the same numeric channel
ID; is_disabled_resolving_discord_aliases() and
is_ncm_fully_disabled() treat toggles under either prefix as equivalent.
- feature_toggles.discord_family_channel_key_variants(channel_key)[source]
Return unique
platform:channel_idstrings to check for Discord aliases.The bot adapter uses
discordand the selfbot usesdiscord-selffor the same numeric channel ID. Toggles may be set under either prefix; callers should treat them as equivalent.
- feature_toggles.strip_ncm_surface_layer_from_context(ctx)[source]
Delete the NCM surface-layer keys from a prompt context dict in place.
Implements the
!emotions offdegradation: it pops each of theNCM_SURFACE_LAYER_KEYS(cadence directive/instruction/refinement profile and the limbic/cascade cue blobs) out of ctx so the rendered prompt loses cadence text and limbic surface cues while the underlying limbic respiration keeps running. Mutates ctx directly and returns nothing; only keys that are present are removed.Called when limbic injection has been merged but the channel has emotions disabled: by
prompt_context.py(PromptContextBuilder) on the per-turn injection dict, bymessage_processor/channel_heartbeat.pyon the heartbeat room context, and bytests/test_feature_toggles.py.
- async feature_toggles.is_disabled(redis, feature, channel_key, guild_id=None)[source]
Return
Trueif feature is disabled for the exact channel_key.For default-off features the logic is reversed: disabled when no key exists, enabled only when the key is explicitly created.
- async feature_toggles.is_disabled_resolving_discord_aliases(redis, feature, channel_key, guild_id=None)[source]
Check
is_disabled()across all Discord-alias variants.
- async feature_toggles.set_disabled(redis, feature, channel_key, disabled, guild_id=None)[source]
Persist the on/off state of feature for channel_key in Redis.
- feature_toggles.is_absolute_bypass(config, user_id=None, channel_key=None)[source]
Return
Trueif a user or channel is on a config-level absolute override list.The global escape hatch that forces NCM/limbic/egregore subsystems on (bypassing any per-channel disable) for explicitly allow-listed users or channels. It reads
overall_user_id_absolute_override_listandoverall_channel_id_absolute_override_listoff config viagetattr(so a missing attribute degrades to empty). A user_id matches by string equality against the user list; a channel_key matches either by Discord-alias-expanded key (viadiscord_family_channel_key_variants()) or by comparing the numeric suffix after the first:against each list entry’s suffix, so a bare numeric id, adiscord:key, and adiscord-self:key all resolve alike. Pure config inspection with no I/O.Called widely as a precedence gate before applying per-channel toggles: by
is_ncm_fully_disabled()here, and acrossprompt_context.py,flash_dyadic_mirror.py,ego_ablation.py,lore_amplifier.py,entrainment_loopfield.py, and severalmessage_processormodules (generate_and_send.py,proactive_gates.py,context_injections.py), plus the override test suites.- Parameters:
config (
Any|None) – AConfig-like object exposing the absolute override lists, orNone(in which case this returnsFalse).user_id (
str|int|None) – Optional user id to test against the user override list; stringified before comparison.channel_key (
str|None) – Optional"{platform}:{channel_id}"(or bare id) to test against the channel override list, alias- and suffix-aware.
- Returns:
Trueif the user or channel is absolutely overridden, elseFalse.- Return type:
- async feature_toggles.is_limbic_respiration_disabled(redis, channel_key, cfg, user_id=None)[source]
True when NCM limbic respiration (inhale/exhale) is disabled for this channel.
NOTE: Channel ‘1424991476668170351’ is explicitly allowed (returns False) and bypasses the disabling effects of overall absolute overrides.
- async feature_toggles.is_ncm_fully_disabled(redis, channel_key, cfg, user_id=None)[source]
Return
Truewhen the entire NCM stack must be off for this channel.The authoritative “is NCM fully disabled” decision, combining static config and live Redis state. It returns
Trueif cfg setsncm_global_disabled, OR ifis_absolute_bypass()flags this user/channel (absolute overrides force the disabled-style respiration path), OR if the channel is listed inncm_fully_disabled_channelsper_ncm_config_matches_channel(). Failing those, when redis is provided it consults the per-channel"ncm"toggle viais_disabled_resolving_discord_aliases(), swallowing and debug-logging any Redis error so a backend hiccup never spuriously disables NCM. The only I/O is that optional Redis read; config checks are in-memory.Called by
is_limbic_respiration_disabled()(after its single-channel allow-list carve-out), and directly by the inference/heartbeat paths inmessage_processor/generate_and_send.pyandmessage_processor/channel_heartbeat.py, plus the toggle/override test suites.- Parameters:
redis (Redis | None) – Optional async Redis client for the per-channel toggle check; when
Noneonly config is consulted.channel_key (str) – The
"{platform}:{channel_id}"key under evaluation.cfg (Any | None) – Optional
Config-like object supplying the global flag, override lists, and disabled-channel set.user_id (str | int | None) – Optional user id forwarded to
is_absolute_bypass().
- Returns:
Trueif NCM is fully disabled for this channel, elseFalse.- Return type:
bool
- async feature_toggles.check_toggle_permission(msg, config, redis=None)[source]
Return
Trueif the user is allowed to toggle features.Allowed when any of the following are true:
The user is a bot admin (
config.admin_user_ids).The user has the
CTX_MANAGEorGUILD_ADMINprivilege bit.The channel is a DM.
- Return type:
bool
- Parameters:
msg (IncomingMessage)
config (Config)
redis (Redis | None)