YujunZhou/tellonce / codex
tellonce
VerifiedUse to view, explain, correct, delete or reorganize the user's saved preferences, or to record one by hand when automatic recording is off; learning and rule injection otherwise run automatically through Codex hooks.
tellonce_codex/mode.py
View on GitHubfrom __future__ import annotations
from dataclasses import dataclass
import json
from pathlib import Path
@dataclass(frozen=True)
class Mode:
mode: str = "audit_only"
hooks: str = "disabled"
blocking: bool = False
wrapper_seen: bool = False
# Rank for monotonic transitions.
# Mode must only progress forward; downgrade is opt-in via allow_downgrade=True
# (e.g. test fixtures). wrapper_seen is also latch-only (True stays True).
_MODE_RANK = {"audit_only": 0, "wrapper": 1, "blocking": 2}
class ModeDowngradeError(ValueError):
"""Raised when write_mode would downgrade the persisted mode."""
def write_mode(
state_root: Path,
mode: str = "audit_only",
wrapper_seen: bool = False,
hooks: str = "disabled",
allow_downgrade: bool = False,
) -> Mode:
# Lazy import to break circular dep with ledger (which imports mode for tests).
from .ledger import secure_mkdir, secure_write_text
secure_mkdir(state_root)
if not allow_downgrade and (state_root / "mode.json").is_file():
try:
prior = load_mode(state_root)
except Exception:
prior = None
if prior is not None:
prior_rank = _MODE_RANK.get(prior.mode, -1)
new_rank = _MODE_RANK.get(mode, -1)
if prior_rank >= 0 and new_rank >= 0 and new_rank < prior_rank:
raise ModeDowngradeError(
f"refusing to downgrade mode {prior.mode!r} -> {mode!r}; "
f"pass allow_downgrade=True if intentional (e.g. test reset)"
)
# wrapper_seen latches True.
if prior.wrapper_seen and not wrapper_seen:
wrapper_seen = True
data = Mode(
mode=mode,
hooks=hooks,
blocking=(mode == "blocking"),
wrapper_seen=wrapper_seen,
)
secure_write_text(state_root / "mode.json", json.dumps(data.__dict__, indent=2) + "\n", atomic=True)
return data
def load_mode(state_root: Path) -> Mode:
path = state_root / "mode.json"
if not path.is_file():
return Mode()
data = json.loads(path.read_text(encoding="utf-8"))
return Mode(
mode=data.get("mode", "audit_only"),
hooks=data.get("hooks", "disabled"),
blocking=bool(data.get("blocking", False)),
wrapper_seen=bool(data.get("wrapper_seen", False)),
)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 323k | Updated | Claude CodeCodex | Verified | Install |