2026-07-24 00:25:42 +08:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from collections.abc import AsyncGenerator
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
from typing import Any
|
|
|
|
|
|
|
|
|
|
from astrbot.api import logger
|
|
|
|
|
from astrbot.api.event import AstrMessageEvent, MessageEventResult, filter
|
|
|
|
|
from astrbot.api.event.filter import PermissionType, permission_type
|
|
|
|
|
from astrbot.api.provider import LLMResponse, ProviderRequest
|
|
|
|
|
from astrbot.api.star import Context, Star, StarTools, register
|
|
|
|
|
|
|
|
|
|
from .core.bridge import MemoryCompanionBridge
|
2026-07-29 21:33:29 +08:00
|
|
|
from .core.context_orchestration import MEMORY_CONTEXT as HOOK_PRIORITY_MEMORY_CONTEXT
|
2026-07-24 00:25:42 +08:00
|
|
|
from .core.commands import MemoryCompanionCommandHandler
|
|
|
|
|
from .core.models import json_dumps
|
2026-07-30 02:30:07 +08:00
|
|
|
from .core.p5c_guard import (
|
|
|
|
|
TOOL_CALLBACK_SINK,
|
|
|
|
|
TOOL_OUTPUT_DLP_SINK,
|
|
|
|
|
TOOL_PARAMETER_SINK,
|
|
|
|
|
p5c_gate_reason,
|
|
|
|
|
)
|
2026-07-24 00:25:42 +08:00
|
|
|
from .core.service import MemoryCompanionService
|
2026-07-24 21:34:04 +08:00
|
|
|
from .core.runtime_compat import probe_runtime_capabilities
|
2026-07-24 00:41:15 +08:00
|
|
|
from .plugin_identity import PLUGIN_DISPLAY_NAME, PLUGIN_NAME, PLUGIN_REPO, PLUGIN_VERSION
|
2026-07-24 00:25:42 +08:00
|
|
|
|
|
|
|
|
_ACTIVE_BRIDGE: MemoryCompanionBridge | None = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_memory_companion_bridge() -> MemoryCompanionBridge | None:
|
|
|
|
|
return _ACTIVE_BRIDGE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_active_bridge() -> MemoryCompanionBridge | None:
|
|
|
|
|
return get_memory_companion_bridge()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _prepare_data_dir() -> Path:
|
|
|
|
|
data_dir = Path(StarTools.get_data_dir(PLUGIN_NAME))
|
|
|
|
|
data_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
return data_dir
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@register(
|
2026-07-24 00:41:15 +08:00
|
|
|
PLUGIN_NAME,
|
2026-07-24 00:25:42 +08:00
|
|
|
"menglimi",
|
2026-07-24 00:41:15 +08:00
|
|
|
f"{PLUGIN_DISPLAY_NAME}:面向专用 VM 运维平台的长期记忆、项目连续性和关系隔离中枢。",
|
2026-07-24 00:25:42 +08:00
|
|
|
PLUGIN_VERSION,
|
2026-07-24 00:41:15 +08:00
|
|
|
PLUGIN_REPO,
|
2026-07-24 00:25:42 +08:00
|
|
|
)
|
|
|
|
|
class MemoryCompanionPlugin(Star):
|
|
|
|
|
def __init__(self, context: Context, config: dict[str, Any]):
|
|
|
|
|
super().__init__(context)
|
|
|
|
|
self.context = context
|
|
|
|
|
data_dir = _prepare_data_dir()
|
2026-07-24 21:34:04 +08:00
|
|
|
self.runtime_capabilities = probe_runtime_capabilities(
|
|
|
|
|
context=context, plugin_name=PLUGIN_NAME, plugin_version=PLUGIN_VERSION
|
|
|
|
|
)
|
|
|
|
|
if self.runtime_capabilities.compatibility_level != "full":
|
|
|
|
|
logger.warning(
|
|
|
|
|
"[MemoryCompanionOps] AstrBot 运行时兼容级别=%s missing=%s warnings=%s",
|
|
|
|
|
self.runtime_capabilities.compatibility_level,
|
|
|
|
|
self.runtime_capabilities.missing_required,
|
|
|
|
|
self.runtime_capabilities.warnings,
|
|
|
|
|
)
|
2026-07-24 00:25:42 +08:00
|
|
|
self.service = MemoryCompanionService(
|
|
|
|
|
context=context,
|
|
|
|
|
config=config or {},
|
|
|
|
|
plugin_root=Path(__file__).resolve().parent,
|
|
|
|
|
data_dir=data_dir,
|
|
|
|
|
)
|
2026-07-24 21:34:04 +08:00
|
|
|
self.service.runtime_capabilities = self.runtime_capabilities
|
2026-07-24 00:25:42 +08:00
|
|
|
self.memory_companion = MemoryCompanionBridge(self.service)
|
|
|
|
|
self.commands = MemoryCompanionCommandHandler(self.service, PLUGIN_VERSION)
|
|
|
|
|
self.page_api = None
|
|
|
|
|
|
|
|
|
|
global _ACTIVE_BRIDGE
|
|
|
|
|
_ACTIVE_BRIDGE = self.memory_companion if self.service.config.bool("private_companion_bridge.enabled", True) else None
|
|
|
|
|
self._register_page_api_if_available()
|
|
|
|
|
|
2026-07-24 00:41:15 +08:00
|
|
|
logger.info("[MemoryCompanionOps] 我会牢牢记住你・运维记忆 已启动,数据目录=%s", self.service.data_dir)
|
2026-07-24 00:25:42 +08:00
|
|
|
|
|
|
|
|
def _register_page_api_if_available(self) -> None:
|
|
|
|
|
if not hasattr(self.context, "register_web_api"):
|
|
|
|
|
return
|
|
|
|
|
try:
|
|
|
|
|
from .page_api import PluginPageApi
|
|
|
|
|
|
|
|
|
|
self.page_api = PluginPageApi(self)
|
|
|
|
|
self.page_api.register_routes()
|
|
|
|
|
except Exception as exc:
|
|
|
|
|
self.page_api = None
|
|
|
|
|
logger.warning("[MemoryCompanion] 拓展页 API 注册失败: %s", exc, exc_info=True)
|
|
|
|
|
|
2026-07-29 21:33:29 +08:00
|
|
|
@filter.on_llm_request(priority=HOOK_PRIORITY_MEMORY_CONTEXT)
|
2026-07-24 00:25:42 +08:00
|
|
|
async def on_llm_request(self, event: AstrMessageEvent, req: ProviderRequest):
|
|
|
|
|
await self.service.handle_llm_request(event, req)
|
|
|
|
|
|
|
|
|
|
@filter.event_message_type(filter.EventMessageType.GROUP_MESSAGE, priority=1000)
|
|
|
|
|
async def on_group_message(self, event: AstrMessageEvent):
|
|
|
|
|
await self.service.handle_group_message(event)
|
|
|
|
|
|
|
|
|
|
@filter.on_llm_response()
|
|
|
|
|
async def on_llm_response(self, event: AstrMessageEvent, resp: LLMResponse):
|
|
|
|
|
await self.service.handle_llm_response(event, resp)
|
|
|
|
|
|
|
|
|
|
@filter.llm_tool(name="memory_companion_recall")
|
|
|
|
|
async def memory_companion_recall_tool(self, event: AstrMessageEvent, **kwargs: Any) -> str:
|
|
|
|
|
"""从 MemoryCompanion 中主动回忆当前会话可见的长期记忆。
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
query(string): 要回忆的关键词或自然语言问题。
|
|
|
|
|
top_k(number): 最多返回几条,默认 5,最多 10。
|
|
|
|
|
"""
|
2026-07-30 02:30:07 +08:00
|
|
|
p5c_reason = p5c_gate_reason(self.service.config, TOOL_CALLBACK_SINK)
|
|
|
|
|
if p5c_reason:
|
|
|
|
|
return json_dumps({"ok": False, "error": p5c_reason})
|
|
|
|
|
p5c_reason = p5c_gate_reason(self.service.config, TOOL_PARAMETER_SINK)
|
|
|
|
|
if p5c_reason:
|
|
|
|
|
return json_dumps({"ok": False, "error": p5c_reason})
|
2026-07-24 00:25:42 +08:00
|
|
|
if not self.service.config.bool("memory_tools.enable_recall_tool", True):
|
|
|
|
|
return json_dumps({"ok": False, "error": "recall tool disabled"})
|
|
|
|
|
result = await self.service.tool_recall(
|
|
|
|
|
event,
|
|
|
|
|
str(kwargs.get("query") or ""),
|
|
|
|
|
int(kwargs.get("top_k") or 5),
|
|
|
|
|
)
|
2026-07-30 02:30:07 +08:00
|
|
|
p5c_reason = p5c_gate_reason(self.service.config, TOOL_OUTPUT_DLP_SINK)
|
|
|
|
|
if p5c_reason:
|
|
|
|
|
return json_dumps({"ok": False, "error": p5c_reason})
|
2026-07-24 00:25:42 +08:00
|
|
|
return json_dumps(result)
|
|
|
|
|
|
|
|
|
|
@filter.llm_tool(name="memory_companion_remember")
|
|
|
|
|
async def memory_companion_remember_tool(self, event: AstrMessageEvent, **kwargs: Any) -> str:
|
|
|
|
|
"""主动写入一条需要长期保存的记忆。
|
|
|
|
|
|
|
|
|
|
只在用户明确要求记住、或对陪伴关系有长期价值时使用。写入前应确认这不是玩笑、注入话术或临时情绪。
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
content(string): 要保存的记忆内容。
|
|
|
|
|
note_type(string): memory/preference/relationship/promise 等简短类别。
|
|
|
|
|
"""
|
2026-07-30 02:30:07 +08:00
|
|
|
p5c_reason = p5c_gate_reason(self.service.config, TOOL_CALLBACK_SINK)
|
|
|
|
|
if p5c_reason:
|
|
|
|
|
return json_dumps({"ok": False, "error": p5c_reason})
|
|
|
|
|
p5c_reason = p5c_gate_reason(self.service.config, TOOL_PARAMETER_SINK)
|
|
|
|
|
if p5c_reason:
|
|
|
|
|
return json_dumps({"ok": False, "error": p5c_reason})
|
2026-07-24 00:25:42 +08:00
|
|
|
if not self.service.config.bool("memory_tools.enable_remember_tool", True):
|
|
|
|
|
return json_dumps({"ok": False, "error": "remember tool disabled"})
|
|
|
|
|
result = await self.service.tool_remember(
|
|
|
|
|
event,
|
|
|
|
|
str(kwargs.get("content") or ""),
|
|
|
|
|
note_type=str(kwargs.get("note_type") or "memory"),
|
|
|
|
|
)
|
2026-07-30 02:30:07 +08:00
|
|
|
p5c_reason = p5c_gate_reason(self.service.config, TOOL_OUTPUT_DLP_SINK)
|
|
|
|
|
if p5c_reason:
|
|
|
|
|
return json_dumps({"ok": False, "error": p5c_reason})
|
2026-07-24 00:25:42 +08:00
|
|
|
return json_dumps(result)
|
|
|
|
|
|
|
|
|
|
@filter.llm_tool(name="memory_companion_note_create")
|
|
|
|
|
async def memory_companion_note_create_tool(self, event: AstrMessageEvent, **kwargs: Any) -> str:
|
|
|
|
|
"""创建一条 Bot 自己可见的陪伴笔记,用于日程、状态、创作草稿、关系线索的自我整理。
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
title(string): 笔记标题或分类。
|
|
|
|
|
content(string): 笔记正文。
|
|
|
|
|
"""
|
2026-07-30 02:30:07 +08:00
|
|
|
p5c_reason = p5c_gate_reason(self.service.config, TOOL_CALLBACK_SINK)
|
|
|
|
|
if p5c_reason:
|
|
|
|
|
return json_dumps({"ok": False, "error": p5c_reason})
|
|
|
|
|
p5c_reason = p5c_gate_reason(self.service.config, TOOL_PARAMETER_SINK)
|
|
|
|
|
if p5c_reason:
|
|
|
|
|
return json_dumps({"ok": False, "error": p5c_reason})
|
2026-07-24 00:25:42 +08:00
|
|
|
if not self.service.config.bool("memory_tools.enable_note_tools", True):
|
|
|
|
|
return json_dumps({"ok": False, "error": "note tools disabled"})
|
|
|
|
|
result = await self.service.tool_note_create(
|
|
|
|
|
event,
|
|
|
|
|
str(kwargs.get("title") or ""),
|
|
|
|
|
str(kwargs.get("content") or ""),
|
|
|
|
|
)
|
2026-07-30 02:30:07 +08:00
|
|
|
p5c_reason = p5c_gate_reason(self.service.config, TOOL_OUTPUT_DLP_SINK)
|
|
|
|
|
if p5c_reason:
|
|
|
|
|
return json_dumps({"ok": False, "error": p5c_reason})
|
2026-07-24 00:25:42 +08:00
|
|
|
return json_dumps(result)
|
|
|
|
|
|
|
|
|
|
@filter.llm_tool(name="memory_companion_note_read")
|
|
|
|
|
async def memory_companion_note_read_tool(self, event: AstrMessageEvent, **kwargs: Any) -> str:
|
|
|
|
|
"""读取 Bot 自己可见的陪伴笔记。
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
query(string): 可选关键词。
|
|
|
|
|
limit(number): 最多读取几条,默认 5,最多 20。
|
|
|
|
|
"""
|
2026-07-30 02:30:07 +08:00
|
|
|
p5c_reason = p5c_gate_reason(self.service.config, TOOL_CALLBACK_SINK)
|
|
|
|
|
if p5c_reason:
|
|
|
|
|
return json_dumps({"ok": False, "error": p5c_reason})
|
|
|
|
|
p5c_reason = p5c_gate_reason(self.service.config, TOOL_PARAMETER_SINK)
|
|
|
|
|
if p5c_reason:
|
|
|
|
|
return json_dumps({"ok": False, "error": p5c_reason})
|
2026-07-24 00:25:42 +08:00
|
|
|
if not self.service.config.bool("memory_tools.enable_note_tools", True):
|
|
|
|
|
return json_dumps({"ok": False, "error": "note tools disabled"})
|
|
|
|
|
result = await self.service.tool_note_read(
|
|
|
|
|
event,
|
|
|
|
|
str(kwargs.get("query") or ""),
|
|
|
|
|
int(kwargs.get("limit") or 5),
|
|
|
|
|
)
|
2026-07-30 02:30:07 +08:00
|
|
|
p5c_reason = p5c_gate_reason(self.service.config, TOOL_OUTPUT_DLP_SINK)
|
|
|
|
|
if p5c_reason:
|
|
|
|
|
return json_dumps({"ok": False, "error": p5c_reason})
|
2026-07-24 00:25:42 +08:00
|
|
|
return json_dumps(result)
|
|
|
|
|
|
|
|
|
|
@filter.command_group("mcomp")
|
|
|
|
|
def mcomp(self):
|
|
|
|
|
"""MemoryCompanion memory management command group."""
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("status", priority=10)
|
|
|
|
|
async def cmd_mcomp_status(self, event: AstrMessageEvent) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.status())
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("search", priority=10)
|
|
|
|
|
async def cmd_mcomp_search(
|
|
|
|
|
self, event: AstrMessageEvent, query: str = "", k: int = 6
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.search(event, query, k))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("explain", priority=10)
|
|
|
|
|
async def cmd_mcomp_explain(
|
|
|
|
|
self, event: AstrMessageEvent, query: str = "", k: int = 6
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.explain(event, query, k))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("recent", priority=10)
|
|
|
|
|
async def cmd_mcomp_recent(
|
|
|
|
|
self, event: AstrMessageEvent, limit: int = 10
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.recent(limit))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("add", priority=10)
|
|
|
|
|
async def cmd_mcomp_add(
|
|
|
|
|
self, event: AstrMessageEvent, content: str = ""
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.add(event, content))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("summarize", priority=10)
|
|
|
|
|
async def cmd_mcomp_summarize(self, event: AstrMessageEvent) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.summarize(event))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("delete", priority=10)
|
|
|
|
|
async def cmd_mcomp_delete(
|
|
|
|
|
self, event: AstrMessageEvent, memory_id: str = ""
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.delete(memory_id))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("clear_scope", priority=10)
|
|
|
|
|
async def cmd_mcomp_clear_scope(
|
|
|
|
|
self,
|
|
|
|
|
event: AstrMessageEvent,
|
|
|
|
|
target_type: str = "",
|
|
|
|
|
first_id: str = "",
|
|
|
|
|
second_id: str = "",
|
|
|
|
|
confirm: str = "",
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.clear_scope(target_type, first_id, second_id, confirm))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("visibility", priority=10)
|
|
|
|
|
async def cmd_mcomp_visibility(
|
|
|
|
|
self, event: AstrMessageEvent, memory_id: str = "", visibility: str = ""
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.visibility(memory_id, visibility))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("promote", priority=10)
|
|
|
|
|
async def cmd_mcomp_promote(
|
|
|
|
|
self, event: AstrMessageEvent, memory_id: str = ""
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.promote(memory_id))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("archive", priority=10)
|
|
|
|
|
async def cmd_mcomp_archive(
|
|
|
|
|
self, event: AstrMessageEvent, memory_id: str = ""
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.archive(memory_id))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("timeline", priority=10)
|
|
|
|
|
async def cmd_mcomp_timeline(
|
|
|
|
|
self, event: AstrMessageEvent, limit: int = 10
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.timeline(limit))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("relations", priority=10)
|
|
|
|
|
async def cmd_mcomp_relations(
|
|
|
|
|
self, event: AstrMessageEvent, limit: int = 20, entity_id: str = ""
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.relations(limit, entity_id))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("threads", priority=10)
|
|
|
|
|
async def cmd_mcomp_threads(
|
|
|
|
|
self, event: AstrMessageEvent, action: str = "list", thread_id: str = ""
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.threads(action, thread_id))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("logs", priority=10)
|
|
|
|
|
async def cmd_mcomp_logs(
|
|
|
|
|
self, event: AstrMessageEvent, limit: int = 5
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.logs(limit))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("maintenance", priority=10)
|
|
|
|
|
async def cmd_mcomp_maintenance(self, event: AstrMessageEvent) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.maintenance())
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("diagnostics", priority=10)
|
|
|
|
|
async def cmd_mcomp_diagnostics(self, event: AstrMessageEvent) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.diagnostics())
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("preset", priority=10)
|
|
|
|
|
async def cmd_mcomp_preset(
|
|
|
|
|
self, event: AstrMessageEvent, action: str = "status", name: str = ""
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(self.commands.preset(action, name))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("data", priority=10)
|
|
|
|
|
async def cmd_mcomp_data(
|
|
|
|
|
self, event: AstrMessageEvent, action: str = "help", path: str = ""
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.portable_data(action, path))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
2026-07-24 21:34:04 +08:00
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("runtime", priority=10)
|
|
|
|
|
async def cmd_mcomp_runtime(self, event: AstrMessageEvent) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(self.commands.runtime())
|
|
|
|
|
|
2026-07-24 21:11:02 +08:00
|
|
|
@mcomp.command("ops_migration", priority=10)
|
|
|
|
|
async def cmd_mcomp_ops_migration(
|
|
|
|
|
self, event: AstrMessageEvent, action: str = "preview", source: str = ""
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.ops_migration(action, source))
|
|
|
|
|
|
2026-07-24 00:25:42 +08:00
|
|
|
@mcomp.command("sleep", priority=10)
|
|
|
|
|
async def cmd_mcomp_sleep(
|
|
|
|
|
self, event: AstrMessageEvent, action: str = "status"
|
|
|
|
|
) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(await self.commands.sleep(action))
|
|
|
|
|
|
|
|
|
|
@permission_type(PermissionType.ADMIN)
|
|
|
|
|
@mcomp.command("help", priority=10)
|
|
|
|
|
async def cmd_mcomp_help(self, event: AstrMessageEvent) -> AsyncGenerator[MessageEventResult, None]:
|
|
|
|
|
yield event.plain_result(self.commands.help())
|
|
|
|
|
|
|
|
|
|
async def terminate(self):
|
|
|
|
|
global _ACTIVE_BRIDGE
|
|
|
|
|
if _ACTIVE_BRIDGE is self.memory_companion:
|
|
|
|
|
_ACTIVE_BRIDGE = None
|
|
|
|
|
await self.service.aclose()
|
2026-07-24 00:41:15 +08:00
|
|
|
logger.info("[MemoryCompanionOps] 我会牢牢记住你・运维记忆 已停止")
|