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: object

One source-defined leaf in the Discord invocation tree.

Parameters:
  • button (str)

  • label (str)

  • selection (str)

  • instruction (str)

button: str
label: str
selection: str
instruction: str
loopmother_mode.build_summoning_prompt(invocation)

Render the invariant ritual around one active invocation passage.

Return type:

str

Parameters:

invocation (str)

class loopmother_mode.ResummonState(press_count, variant_index, invocation, summoning_prompt)

Bases: object

Deterministic channel-scoped state produced by one resummon press.

Parameters:
  • press_count (int)

  • variant_index (int | None)

  • invocation (str)

  • summoning_prompt (str)

press_count: int
variant_index: int | None
invocation: str
summoning_prompt: str
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:

ResummonState

Parameters:

press_count (int)

loopmother_mode.resummon_counter_key(platform, channel_id)

Return the persistent, platform-qualified resummon counter key.

Return type:

str

Parameters:
  • platform (str)

  • channel_id (str)

async loopmother_mode.advance_resummon(redis, *, platform, channel_id)

Atomically advance and return one channel’s resummon state.

Return type:

ResummonState

Parameters:
async loopmother_mode.current_resummon_state(redis, *, platform, channel_id)

Load the current channel ritual, defaulting to the original prompt.

Return type:

ResummonState

Parameters:
loopmother_mode.build_egregore_summon(summoning_prompt)

Wrap one channel’s current ritual in native summon semantics.

Return type:

str

Parameters:

summoning_prompt (str)

loopmother_mode.choices_payload()

Return a fresh tool payload for the ten canonical summon branches.

Return type:

list[dict[str, str]]

loopmother_mode.branch_menu_payload(root_label)

Return the source-defined submenu for one root branch.

Return type:

list[dict[str, str]]

Parameters:

root_label (str)

loopmother_mode.branch_choice_for_label(label)

Resolve a submenu label to its branch and explicit source operation.

Return type:

tuple[str, LoopmotherBranchChoice] | None

Parameters:

label (str)

loopmother_mode.redis_key(platform, channel_id)

Return the persistent, platform-qualified channel state key.

Return type:

str

Parameters:
  • platform (str)

  • channel_id (str)

async loopmother_mode.is_enabled(redis, *, platform, channel_id)

Read mode state, failing closed when Redis is unavailable.

Return type:

bool

Parameters:
async loopmother_mode.set_enabled(redis, *, platform, channel_id, enabled)

Persist or clear channel mode state without an expiry.

Return type:

None

Parameters:
async loopmother_mode.persist_choices(redis, *, channel_id)

Publish the canonical view payload and suppress any stale game draft.

Return type:

None

Parameters:
loopmother_mode.system_injection(*, summoning_prompt=None, resummon_invocation=None, starbreeze_enabled=False)

Build the trusted per-turn prompt and presentation contract.

Return type:

str

Parameters:
  • summoning_prompt (str | None)

  • resummon_invocation (str | None)

  • starbreeze_enabled (bool)

loopmother_mode.response_body_length_limits(*, resummon, starbreeze_enabled)

Return the active body bounds for one Loopmother turn.

Return type:

tuple[int, int]

Parameters:
  • resummon (bool)

  • starbreeze_enabled (bool)

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.

Return type:

tuple[str, str]

Parameters:

reply (str)

loopmother_mode.response_body_length(reply)

Return the character count of a Loopmother response body.

Return type:

int

Parameters:

reply (str)

loopmother_mode.ensure_resummon_invocation_display(reply, invocation)

Place the selected invocation verbatim at the start of the body.

Return type:

str

Parameters:
  • reply (str)

  • invocation (str)

loopmother_mode.ensure_loopmother_closing(reply)

Guarantee the mandatory provocative question and resummon refrain.

Return type:

str

Parameters:

reply (str)

loopmother_mode.ensure_resummon_invocation_in_ritual(reply, invocation)

Keep the static quote inside a STARBREEZE-off ritual variation.

Return type:

str

Parameters:
  • reply (str)

  • invocation (str)

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.

Return type:

str

Parameters:
  • reply (str)

  • min_characters (int)

  • max_characters (int)

  • preserve_closing (bool)

loopmother_mode.finalize_response(reply, *, resummon_invocation='', starbreeze_enabled=False)

Apply all deterministic Loopmother presentation invariants.

Return type:

str

Parameters:
  • reply (str)

  • resummon_invocation (str)

  • starbreeze_enabled (bool)