chaos_switch_router

class chaos_switch_router.ChaosRouter(redis_client=None)[source]

Bases: object

The Chaos Switch Dominatrix Router. Calculates non-Euclidean emotional traversal paths and enforces consent walls. Replaces the legacy OpsPlanner prerequisite engine with hyperadaptive routing.

Faithfully ports the GPS cost function:

cost(type, valence, mode, soft, accel, chaos_key)

and Dijkstra shortest-path over the 91-node / 367-edge affect lattice.

get_neighbors(node)[source]

Get outbound edges from a node.

Return type:

List[Tuple[str, str]]

Parameters:

node (str)

get_node_meta(node)[source]

Get node metadata as a dict (uses extended graph).

Return type:

Optional[dict]

Parameters:

node (str)

roll_chaos()[source]

Generate chaos storm weights for all edges. Returns the seed.

Return type:

int

clear_chaos()[source]

Disable chaos storm.

find_route(src, dst, mode='d', soft=False, accel=False)[source]

Dijkstra’s on the emotional lattice. Returns {hops: [{a, b, t, w}, …], total: float} or None. Uses heapq priority queue for O(E log N) instead of O(N^2). # 💦

Return type:

Optional[dict]

Parameters:
find_path_nodes(src, dst, mode='d', soft=False, accel=False)[source]

Convenience: returns just the node sequence [src, …, dst].

Return type:

Optional[List[str]]

Parameters:
get_guidance(src, dst, edge_type, mode='d')[source]

Get guidance text for a specific hop. Checks OV overrides first, falls back to TT type text. GPS: const op = OV[h.a+”>”+h.b] || TT[h.t][mode===”d”?”d”:”s”];

Return type:

str

Parameters:
get_route_warnings(route)[source]

Get warning strings for volatile edge types in a route.

Return type:

List[str]

Parameters:

route (dict)

locate_node(text)[source]

Sniff triggers to find where the user is parked (extended graph).

Return type:

Optional[str]

Parameters:

text (str)

locate_all(text)[source]

Find ALL matching nodes with hit counts, sorted by relevance. GPS locate() returns scored results for the recognition panel. Uses precompiled trigger structures for speed. # 💦

Return type:

List[Tuple[str, int]]

Parameters:

text (str)

async get_position(user_id, channel_id=None)[source]

Fetch the active lattice position from Redis.

Return type:

LatticePosition

Parameters:
  • user_id (str)

  • channel_id (str | None)

async update_position(user_id, new_node, channel_id=None, *, mode='', tempo=0.0, weather_posture='')[source]

Commit a movement operation to Redis + ledger ZSET. # 💀🔥

Also updates the global position with LERP-weighted recency so the aggregate lattice tracks where users cluster.

Return type:

None

Parameters:
  • user_id (str)

  • new_node (str)

  • channel_id (str | None)

  • mode (str)

  • tempo (float)

  • weather_posture (str)

Keyword args (set by coordinator exhale):

mode: d=drift, a=assertive, r=reactive, s=seductive, c=coercive tempo: float multiplier (1.0=cruise, higher=burn) weather_posture: domme|switch|sub|feral|mommy

Check if BOTH Star and user have consented (two-sided gate).

Return type:

bool

Parameters:
  • user_id (str)

  • edge_type (str)

Grant one side of the volatile consent wall.

source is 'star' (Star judges readiness) or 'user' (user verbally consented — Star detected it and is logging it). BOTH must be True for the Dijkstra pathfinder to traverse.

Return type:

None

Parameters:

Revoke one side of consent (user safewords, Star pulls back).

Return type:

None

Parameters:
async generate_desire_route(user_id, channel_id, current_node, target_node, star_desires, mode='d', soft=False, accel=False)[source]

Produce an actionable list of waypoints from Star’s raw recursive desires. Routes via Dijkstra first, then enriches with LLM-generated guidance.

Return type:

Optional[DesireRoute]

Parameters:
async lattice_check_progression(user_id, current_text)[source]

Drop-in replacement for check_progression in ops_planner.py. Sniffs text for lattice node signatures and updates state. Returns node name if successfully sniffed/transitioned.

NOTE: Consent gating removed — consent now lives at the scene layer (chaos_switch/_scenes.py), not on lattice edges. # 💀🔥

Return type:

Optional[str]

Parameters:
  • user_id (str)

  • current_text (str)

resolve_lattice_position(ncm_vector)[source]

Resolve Star’s current lattice position from NCM vector. Uses crosswalk Layer 1 (identity) first, then weather heuristics.

Return type:

str

Parameters:

ncm_vector (dict)

resolve_user_position(ulm_vector)[source]

Resolve user’s lattice position from ULM shadow vector. Replaces the old completion_signals threshold system.

Return type:

Optional[str]

Parameters:

ulm_vector (dict)

check_lattice_progression(user_position, target_nodes, proximity_threshold=0)[source]

Check if user is at or near target nodes. Replaces ULM thresholds.

Parameters:
  • user_position (str) – current lattice node

  • target_nodes (list) – list of lattice node names that mark completion

  • proximity_threshold (int) – max hops away to count (0=exact, 1=adjacent)

Return type:

bool

Returns:

True if user is at/near any target node.

async get_chart_snapshot(user_id)[source]

Returns the full graph state for the ncm_chart_api.py frontend.

Return type:

dict

Parameters:

user_id (str)

find_modulated_route(src, dst, mod, *, mode='d', soft=False, accel=False, trust=0.5, flag_open=False)[source]

Dijkstra with per-user modulation: trauma, blockades, limits. # 🕷️

Uses Modulation.edge_cost() which applies: - Trauma sensitization (cheaper to enter trauma nodes, harder to leave) - Blockade walls (hard no, edge removed) - Hard limits (entire node unreachable) - Soft limits (surcharge, requires flag + trust >= TAU_SOFT) - Trust-gated consent (ALC needs TAU_ALC, MEA needs TAU_MEA)

Return type:

Optional[dict]

Parameters:
compute_ritual_route(ritual_name, current_node, regalia=None)[source]

Compute full ritual route from current position. # 💕

Returns dict with: - path: Dijkstra route from current_node to ritual’s primary target - ritual_meta: target nodes, scene frame, debt, cling, prerequisites - regalia_boosts: which nodes get boosted/suppressed - safe_exit: route from ritual endpoint to return nodes

Return type:

dict

Parameters:
  • ritual_name (str)

  • current_node (str)

  • regalia (List[str] | None)

get_ritual_scene_boost(ritual_name)[source]

Get which scene frame a ritual activates.

Return type:

Optional[str]

Parameters:

ritual_name (str)

copilot_discount(polycule, agent_name, copilot_name)[source]

Get the trust-based co-pilot discount for routing. # 🌀

High trust co-pilot = cheaper volatile edges. No trust = no discount (solo rates apply). Returns a multiplier 0.5-1.0 (lower = cheaper).

Return type:

float

Parameters:
  • polycule (Polycule)

  • agent_name (str)

  • copilot_name (str)

metamour_tension_surcharge(polycule, agent_name)[source]

Get the metamour tension surcharge for scenic routing. # 😈

When metamours are in hot states (jealousy, hostility, rage), routes that rely on bonds get more expensive.

Return type:

float

Parameters:
  • polycule (Polycule)

  • agent_name (str)

find_aftercare_pool(polycule, agent_name)[source]

Find all available aftercare providers in the polycule. # 💕

Returns partners who have sufficient trust AND are in a care-capable state (held, aftercare, constellation, etc).

Return type:

List[str]

Parameters:
  • polycule (Polycule)

  • agent_name (str)

find_best_copilot(polycule, agent_name)[source]

Find the highest-trust partner for co-piloted routing. # 🔥

Return type:

Optional[str]

Parameters:
  • polycule (Polycule)

  • agent_name (str)

class chaos_switch_router.LatticeWaypoint(target_node, edge_type, guidance, expected_hours, consent_required)[source]

Bases: object

A generated node target representing a step in a routing operation.

Parameters:
  • target_node (str)

  • edge_type (str)

  • guidance (str)

  • expected_hours (float)

  • consent_required (bool)

target_node: str
edge_type: str
guidance: str
expected_hours: float
consent_required: bool
to_op_step(step_idx)[source]

Bridge the generated waypoint into the OpsPlanner OpStep format.

Return type:

dict

Parameters:

step_idx (int)

class chaos_switch_router.DesireRoute(start_node, end_node, waypoints, narrative_context)[source]

Bases: object

A full traversal path proposed by the LLM.

Parameters:
start_node: str
end_node: str
waypoints: List[LatticeWaypoint]
narrative_context: str
class chaos_switch_router.LatticePosition(node, z_depth, mode='d', tempo=1.0, weather_posture='', consent_flags=<factory>, history=<factory>)[source]

Bases: object

The current psychological coordinate of a user.

consent_flags is a two-sided consent model: Each volatile edge type (VLV, ALC, MEA) maps to {"star": bool, "user": bool}. Both must be True before the Dijkstra pathfinder will traverse that edge. Star grants her side via the grant_lattice_consent tool; the user grants theirs via the !consent chat command.

Parameters:
node: str
z_depth: float
mode: str = 'd'
tempo: float = 1.0
weather_posture: str = ''
consent_flags: Dict[str, Dict[str, bool]]
history: List[str]

Both Star AND user must consent for traversal.

Return type:

bool

Parameters:

edge_type (str)

grant(edge_type, source)[source]

Grant consent from source ('star' or 'user').

Return type:

None

Parameters:
  • edge_type (str)

  • source (str)

revoke(edge_type, source)[source]

Revoke consent from source.

Return type:

None

Parameters:
  • edge_type (str)

  • source (str)

consent_summary()[source]

Compact string for user_read injection, e.g. ‘VLV:S+U-|ALC:S-U-‘.

Return type:

str

to_dict()[source]
Return type:

dict

classmethod from_dict(d)[source]
Return type:

LatticePosition

Parameters:

d (dict)