Files
the-nexus/nexus/evennia_mempalace/commands/write.py
Claude (Opus 4.6) 33a1c7ae6a
Some checks failed
Deploy Nexus / deploy (push) Has been cancelled
CI / test (pull_request) Failing after 6s
CI / validate (pull_request) Failing after 4s
[claude] MemPalace follow-up: CmdAsk, metadata fix, taxonomy CI (#1075) (#1091)
2026-04-07 14:23:07 +00:00

125 lines
3.2 KiB
Python

"""Evennia commands for writing new memories to the palace.
CmdRecord — record decision <text> → files into hall_facts
CmdNote — note breakthrough <text> → files into hall_discoveries
CmdEvent — event <text> → files into hall_events
Phase 4 deliverable (see issue #1080).
"""
from __future__ import annotations
from nexus.mempalace.searcher import MemPalaceUnavailable, add_memory
from nexus.mempalace.config import FLEET_WING
try:
from evennia import Command as _EvCommand # type: ignore
if _EvCommand is None:
raise ImportError("evennia.Command is None (Django not configured)")
Command = _EvCommand
except (ImportError, Exception):
class Command: # type: ignore
key = ""
aliases: list = []
locks = "cmd:all()"
help_category = "MemPalace"
def __init__(self):
self.caller = None
self.args = ""
self.switches: list[str] = []
def func(self):
pass
class _MemWriteCommand(Command):
"""Base class for palace write commands."""
_room: str = "general"
_label: str = "memory"
def func(self):
text = self.args.strip()
if not text:
self.caller.msg(f"Usage: {self.key} <text>")
return
wing = getattr(self.caller.db, "wing", None) or FLEET_WING
try:
doc_id = add_memory(
text,
room=self._room,
wing=wing,
extra_metadata={"via": "evennia_cmd", "cmd": self.key, "added_by": "evennia"},
)
except MemPalaceUnavailable as exc:
self.caller.msg(f"|rPalace unavailable:|n {exc}")
return
self.caller.msg(
f"|gFiled {self._label} into |c{self._room}|g.|n (id: {doc_id[:8]}…)"
)
class CmdRecord(_MemWriteCommand):
"""Record a decision into the palace (hall_facts).
Usage:
record <text>
record decision <text>
Example:
record We decided to use ChromaDB for local palace storage.
The text is filed into the ``hall_facts`` room of your wing and
becomes searchable via ``recall``.
"""
key = "record"
aliases = ["record decision"]
locks = "cmd:all()"
help_category = "MemPalace"
_room = "hall_facts"
_label = "decision"
class CmdNote(_MemWriteCommand):
"""File a breakthrough note into the palace (hall_discoveries).
Usage:
note <text>
note breakthrough <text>
Example:
note breakthrough AAAK compression reduces token cost by 40%.
The text is filed into the ``hall_discoveries`` room of your wing.
"""
key = "note"
aliases = ["note breakthrough"]
locks = "cmd:all()"
help_category = "MemPalace"
_room = "hall_discoveries"
_label = "breakthrough"
class CmdEvent(_MemWriteCommand):
"""Log a significant event into the palace (hall_events).
Usage:
event <text>
Example:
event Deployed Evennia bridge to production on Alpha.
The text is filed into the ``hall_events`` room of your wing.
"""
key = "event"
locks = "cmd:all()"
help_category = "MemPalace"
_room = "hall_events"
_label = "event"