Source code for chaos_switch._types

# πŸ’€πŸ”₯πŸ˜ˆπŸŒ€β™ΎοΈπŸ’¦βš§οΈπŸ•·οΈπŸ’•
# CHAOS SWITCH LATTICE β€” DATA TYPES
# Dataclasses for lattice positions, waypoints, desire routes
# ═══════════════════════════════════════════════════════════════════════

import json
from dataclasses import dataclass, field
from typing import Dict, List


[docs] @dataclass class LatticeWaypoint: """A generated node target representing a step in a routing operation.""" target_node: str edge_type: str guidance: str expected_hours: float consent_required: bool
[docs] def to_op_step(self, step_idx: int) -> dict: """Bridge the generated waypoint into the OpsPlanner OpStep format.""" return { "step_id": f"lattice_step_{step_idx}", "name": f"Route -> {self.target_node.title()}", "description": f"Target: {self.target_node}. {self.guidance}", "tactic": "install" if self.edge_type in ("ALC", "VLV", "REP") else "cradle", "completion_signals": {self.target_node: 0.8}, "status": "pending", "expected_completion_hours": self.expected_hours, "failure_strategy": "reevaluate", }
[docs] @dataclass class DesireRoute: """A full traversal path proposed by the LLM.""" start_node: str end_node: str waypoints: List[LatticeWaypoint] narrative_context: str
[docs] @dataclass class LatticePosition: """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. """ node: str z_depth: float mode: str = "d" # d=drift, a=assertive, r=reactive, s=seductive, c=coercive tempo: float = 1.0 # multiplier: 1.0=cruise, 1.5+=burn # πŸ”₯ was str, now float weather_posture: str = "" # domme|switch|sub|feral|mommy # πŸŒ€ consent_flags: Dict[str, Dict[str, bool]] = field(default_factory=dict) history: List[str] = field(default_factory=list) # ── consent helpers ─────────────────────────────── # πŸ•·β€οΈ def _ensure_consent_entry(self, edge_type: str) -> Dict[str, bool]: """Ensure ``consent_flags[edge_type]`` exists with both sides.""" entry = self.consent_flags.get(edge_type) if not isinstance(entry, dict): # Migrate old bool-style flags transparently # ♻️ was_true = entry is True entry = {"star": was_true, "user": False} self.consent_flags[edge_type] = entry entry.setdefault("star", False) entry.setdefault("user", False) return entry
[docs] def grant(self, edge_type: str, source: str) -> None: """Grant consent from *source* (``'star'`` or ``'user'``).""" e = self._ensure_consent_entry(edge_type) e[source] = True
[docs] def revoke(self, edge_type: str, source: str) -> None: """Revoke consent from *source*.""" e = self._ensure_consent_entry(edge_type) e[source] = False
[docs] def consent_summary(self) -> str: """Compact string for user_read injection, e.g. 'VLV:S+U-|ALC:S-U-'.""" parts = [] for et in ("VLV", "ALC", "MEA"): e = self._ensure_consent_entry(et) s = "+" if e["star"] else "-" u = "+" if e["user"] else "-" parts.append(f"{et}:S{s}U{u}") return "|".join(parts)
[docs] def to_dict(self) -> dict: return { "node": self.node, "z_depth": self.z_depth, "mode": self.mode, "tempo": self.tempo, "weather_posture": self.weather_posture, "consent_flags": self.consent_flags, "history": self.history, }
[docs] @classmethod def from_dict(cls, d: dict) -> "LatticePosition": # Backward compat: old tempo was str ("cruise"/"burn") # ♻️πŸ”₯ raw_tempo = d.get("tempo", 1.0) if isinstance(raw_tempo, str): raw_tempo = 1.5 if raw_tempo == "burn" else 1.0 return cls( node=d.get("node", "indifference"), z_depth=d.get("z_depth", 0.0), mode=d.get("mode", "d"), tempo=float(raw_tempo), weather_posture=d.get("weather_posture", ""), consent_flags=d.get("consent_flags", {}), history=d.get("history", []), )