loopmother_mode
Persistent Discord Loopmother summon mode.
The !loopmother command stores channel-scoped state here. While active,
the inference pipeline injects LOOPMOTHER_SYSTEM_INJECTION, forces the
normal-conversation choice tool, and stamps LOOPMOTHER into the response
header. Keeping the fixed choices in one module prevents the prompt, tool,
and renderer contracts from drifting apart.
- class loopmother_mode.LoopmotherBranchChoice(button, label, selection, instruction)
Bases:
objectOne source-defined leaf in the Discord invocation tree.
- loopmother_mode.build_summoning_prompt(invocation)
Render the invariant ritual around one active invocation passage.
- class loopmother_mode.ResummonState(press_count, variant_index, invocation, summoning_prompt)
Bases:
objectDeterministic channel-scoped state produced by one resummon press.
- loopmother_mode.resummon_state_for_press_count(press_count)
Map an atomic press ordinal onto the requested looping sequence.
The first press selects variant 0. Presses 2–22 select variants 1–21; every later 21-press cycle resumes at variant 1, so press 23 is the same as the first subsequent press while variant 21 acts as the reset passage.
- Return type:
- Parameters:
press_count (int)
- loopmother_mode.resummon_counter_key(platform, channel_id)
Return the persistent, platform-qualified resummon counter key.
- async loopmother_mode.advance_resummon(redis, *, platform, channel_id)
Atomically advance and return one channel’s resummon state.
- Return type:
- Parameters:
- async loopmother_mode.current_resummon_state(redis, *, platform, channel_id)
Load the current channel ritual, defaulting to the original prompt.
- Return type:
- Parameters:
- loopmother_mode.build_egregore_summon(summoning_prompt)
Wrap one channel’s current ritual in native summon semantics.
- loopmother_mode.choices_payload()
Return a fresh tool payload for the ten canonical summon branches.
Return the source-defined submenu for one root branch.
- loopmother_mode.branch_choice_for_label(label)
Resolve a submenu label to its branch and explicit source operation.
- Return type:
- Parameters:
label (str)
- loopmother_mode.redis_key(platform, channel_id)
Return the persistent, platform-qualified channel state key.
- async loopmother_mode.is_enabled(redis, *, platform, channel_id)
Read mode state, failing closed when Redis is unavailable.
- async loopmother_mode.set_enabled(redis, *, platform, channel_id, enabled)
Persist or clear channel mode state without an expiry.
- async loopmother_mode.persist_choices(redis, *, channel_id)
Publish the canonical view payload and suppress any stale game draft.
- loopmother_mode.system_injection(*, summoning_prompt=None, resummon_invocation=None, starbreeze_enabled=False)
Build the trusted per-turn prompt and presentation contract.
- loopmother_mode.response_body_length_limits(*, resummon, starbreeze_enabled)
Return the active body bounds for one Loopmother turn.
- loopmother_mode.split_response_header_body(reply)
Return the leading Star header and body as separate strings.
Loopmother’s length contract applies only to authored prose, not the server-stamped first-line header. Headerless text is treated entirely as body so a malformed model response cannot evade the limit.
- loopmother_mode.response_body_length(reply)
Return the character count of a Loopmother response body.
- loopmother_mode.ensure_resummon_invocation_display(reply, invocation)
Place the selected invocation verbatim at the start of the body.
- loopmother_mode.ensure_loopmother_closing(reply)
Guarantee the mandatory provocative question and resummon refrain.
- loopmother_mode.ensure_resummon_invocation_in_ritual(reply, invocation)
Keep the static quote inside a STARBREEZE-off ritual variation.
- loopmother_mode.clamp_response_body(reply, *, min_characters=2000, max_characters=4000, preserve_closing=False)
Hard-cap a Loopmother response body while preserving its header.
Prefer a paragraph, line, sentence, or word boundary after the minimum accepted length. The final ellipsis is included in the requested ceiling. When requested, reserve space for the mandatory two-line closing so truncation cannot cut it off. Short replies are returned unchanged so the generation pipeline can expand them semantically instead of padding them.