From 04854669fdaa6932a695f4fd32077563a8de3c40 Mon Sep 17 00:00:00 2001 From: YokiiroBW Date: Fri, 24 Jul 2026 00:41:15 +0800 Subject: [PATCH] feat: initialize operations memory branch --- CHANGELOG.md | 8 +++++ README.md | 14 ++++---- benchmarks/run_memory_benchmark.py | 4 +-- core/archive_contract.py | 2 +- core/astrbot_compat.py | 4 +-- core/chat_import.py | 2 ++ core/operations.py | 5 +++ core/service.py | 4 +-- docs/错题本.md | 11 ++++++ main.py | 14 ++++---- metadata.yaml | 11 +++--- page_api.py | 58 ++++++++++++++++-------------- plugin_identity.py | 10 ++++++ tests/test_archive_contract.py | 2 +- 14 files changed, 95 insertions(+), 54 deletions(-) create mode 100644 plugin_identity.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 36d136a..e578558 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ 本项目遵循面向用户体验的版本记录。日期使用北京时间。 +## 1.6.2-ops.1 - 2026-07-23 + +- 建立 `ops-main` 专用运维记忆产品分支。 +- 插件身份改为 `astrbot_plugin_memory_companion_ops`,独立注册名、数据目录、扩展页路由和版本。 +- 增加 QQ Official 元数据声明,运维记忆页面和历史导入优先发现 `astrbot_plugin_private_companion_ops`。 +- 保留普通人格插件名称作为一次性迁移和兼容入口。 +- 修复 benchmark 遗留的旧包名引用;运维分支回归测试 `128 passed`。 + ## 1.6.2 - 2026-07-20 ### 共同经历记忆 diff --git a/README.md b/README.md index 3822ed9..8887dbb 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ -# 我会牢牢记住你 +# 我会牢牢记住你・运维记忆 -`astrbot_plugin_memory_companion` 是面向 AstrBot 陪伴体系的记忆陪伴中枢。它不把聊天记录粗暴塞回模型,而是把当前消息、连续对话、长期记忆、Bot 自我时间线、群聊/私聊权限和外部陪伴插件线索分层整理,再在每轮 LLM 请求前生成一份临时、可解释、可排查的记忆包。 +> 当前分支:`ops-main`。这是面向个人 AstrBot VM 运维平台的专用记忆版本,与普通陪伴记忆版使用不同插件身份和数据目录。 -- 插件名:`astrbot_plugin_memory_companion` -- 中文名:`我会牢牢记住你` -- 版本:`1.6.1` -- 适配平台:`aiocqhttp` +`astrbot_plugin_memory_companion_ops` 是面向专用 AstrBot VM 运维平台的记忆与项目连续性中枢。它不把聊天记录粗暴塞回模型,而是把当前消息、连续对话、长期记忆、Bot 自我时间线、群聊/私聊权限和外部陪伴插件线索分层整理,再在每轮 LLM 请求前生成一份临时、可解释、可排查的记忆包。 + +- 插件名:`astrbot_plugin_memory_companion_ops` +- 中文名:`我会牢牢记住你・运维记忆` +- 版本:`1.6.2-ops.1` +- 适配平台:`aiocqhttp`、`qq_official` - AstrBot 版本:`>=4.22.0` - 编码要求:UTF-8 diff --git a/benchmarks/run_memory_benchmark.py b/benchmarks/run_memory_benchmark.py index 66a7ffb..5f61988 100644 --- a/benchmarks/run_memory_benchmark.py +++ b/benchmarks/run_memory_benchmark.py @@ -14,8 +14,8 @@ ROOT = Path(__file__).resolve().parents[1] if str(ROOT.parent) not in sys.path: sys.path.insert(0, str(ROOT.parent)) -from astrbot_plugin_remember_you.core.models import EntityRef, MemoryRecord, SessionContext -from astrbot_plugin_remember_you.core.service import MemoryCompanionService +from astrbot_plugin_memory_companion_ops.core.models import EntityRef, MemoryRecord, SessionContext +from astrbot_plugin_memory_companion_ops.core.service import MemoryCompanionService TARGETS = [ diff --git a/core/archive_contract.py b/core/archive_contract.py index dcec8a8..e97a60a 100644 --- a/core/archive_contract.py +++ b/core/archive_contract.py @@ -7,7 +7,7 @@ from .models import MemoryRecord, clean_text ARCHIVE_API_VERSION = "1.0" SOURCE_NAME = "memory_companion" -SOURCE_VERSION = "1.6.2" +SOURCE_VERSION = "1.6.2-ops.1" _SECRET_PATTERNS = ( (re.compile(r"(?i)\b(password|passwd|pwd)\s*[:=]\s*[^\s,;]+"), r"\1=[REDACTED_SECRET]"), diff --git a/core/astrbot_compat.py b/core/astrbot_compat.py index 9978836..7f6b0cf 100644 --- a/core/astrbot_compat.py +++ b/core/astrbot_compat.py @@ -270,10 +270,10 @@ def _is_temp_or_plugin_context(item: Any) -> bool: metadata = item.get("metadata") if isinstance(metadata, dict): source = str(metadata.get("source") or metadata.get("plugin") or metadata.get("source_plugin") or "") - if source in {"private_companion", "astrbot_plugin_private_companion"}: + if source in {"private_companion", "astrbot_plugin_private_companion_ops", "astrbot_plugin_private_companion"}: return True source = str(item.get("source") or item.get("plugin") or item.get("source_plugin") or "") - return source in {"private_companion", "astrbot_plugin_private_companion"} + return source in {"private_companion", "astrbot_plugin_private_companion_ops", "astrbot_plugin_private_companion"} def _sanitize_context_content(value: Any) -> tuple[Any, bool, bool]: diff --git a/core/chat_import.py b/core/chat_import.py index b38587b..4da478f 100644 --- a/core/chat_import.py +++ b/core/chat_import.py @@ -989,6 +989,8 @@ class HistoricalChatImporter: def _private_api(self) -> Any | None: for module_name in ( + "data.plugins.astrbot_plugin_private_companion_ops.main", + "astrbot_plugin_private_companion_ops.main", "data.plugins.astrbot_plugin_private_companion.main", "astrbot_plugin_private_companion.main", ): diff --git a/core/operations.py b/core/operations.py index 612e998..9aa9a56 100644 --- a/core/operations.py +++ b/core/operations.py @@ -80,6 +80,11 @@ PRESET_LABELS = { CONFLICT_PLUGINS: dict[str, dict[str, str]] = { + "astrbot_plugin_private_companion_ops": { + "level": "coordinated", + "label": "PrivateCompanion Ops", + "reason": "运维人格版已提供专用桥接和重复上下文抑制。", + }, "astrbot_plugin_private_companion": { "level": "coordinated", "label": "PrivateCompanion", diff --git a/core/service.py b/core/service.py index 4d05de2..4c93bc3 100644 --- a/core/service.py +++ b/core/service.py @@ -1938,8 +1938,8 @@ class MemoryCompanionService: payload.update( { "available": True, - "display_name": "我会牢牢记住你", - "plugin_name": "astrbot_plugin_memory_companion", + "display_name": "我会牢牢记住你・运维记忆", + "plugin_name": "astrbot_plugin_memory_companion_ops", "counted_in_private_companion_budget": False, "note": "仅展示记忆插件自身模型消耗,不计入陪伴插件每日 Token 限额。", } diff --git a/docs/错题本.md b/docs/错题本.md index dc3e0f6..eb94ecb 100644 --- a/docs/错题本.md +++ b/docs/错题本.md @@ -111,3 +111,14 @@ - 修复或规避:运维版采用 `astrbot_plugin_memory_companion_ops` 独立身份,并同步修改注册、数据目录、页面路由、Bridge 发现、备份合同和更新源;普通数据只做一次性复制迁移。 - 预防规则:任何长期产品分线都必须同时检查代码分支、插件身份、数据目录、发布包和更新源五层隔离,不能把 Git 分支误当成运行时隔离。 - 验证证据:已核对 `main.py` 与 `page_api.py` 中的 `PLUGIN_NAME`、数据目录和路由用法,并形成 `双分支运维版可行性评估.md`。 + + +## 2026-07-23 — 运维记忆分支建立并完成身份隔离 + +- 阶段:运维分支初始化与第一批代码改造 +- 类型:环境 / 测试 / API契约 +- 现象:源码快照没有 Git 历史;Git 初始化后触发 dubious ownership;系统命令中没有 python;旧 benchmark 仍引用 astrbot_plugin_remember_you。 +- 根因:目录所有者与沙箱执行用户不同;Windows 环境未把 Python 放入 PATH;benchmark 未跟随插件改名。 +- 修复或规避:建立 companion-main 基线、upstream-sync 和 ops-main;Git 使用仓库级 safe.directory;测试使用 Codex bundled Python;benchmark 改用 astrbot_plugin_memory_companion_ops。此前关于“全部测试因旧包名无法收集”的记录在当前基线已被本条取代,当前测试直接引用 core 包。 +- 预防规则:后续版本改名必须同步检查 main、metadata、页面路由、Bridge、历史导入、运维诊断、benchmark 和测试;测试结果必须来自当前分支实际执行。 +- 验证证据:companion-main 基线提交为 2f24824,当前分支为 ops-main;compileall 通过;pytest 结果 128 passed in 13.51s。 diff --git a/main.py b/main.py index 9bd2789..89529b9 100644 --- a/main.py +++ b/main.py @@ -14,9 +14,7 @@ from .core.bridge import MemoryCompanionBridge from .core.commands import MemoryCompanionCommandHandler from .core.models import json_dumps from .core.service import MemoryCompanionService - -PLUGIN_NAME = "astrbot_plugin_memory_companion" -PLUGIN_VERSION = "1.6.2" +from .plugin_identity import PLUGIN_DISPLAY_NAME, PLUGIN_NAME, PLUGIN_REPO, PLUGIN_VERSION _ACTIVE_BRIDGE: MemoryCompanionBridge | None = None @@ -36,11 +34,11 @@ def _prepare_data_dir() -> Path: @register( - "MemoryCompanion", + PLUGIN_NAME, "menglimi", - "我会牢牢记住你:结构化长期记忆、共同自我时间线和关系隔离。", + f"{PLUGIN_DISPLAY_NAME}:面向专用 VM 运维平台的长期记忆、项目连续性和关系隔离中枢。", PLUGIN_VERSION, - "https://github.com/menglimi/astrbot_plugin_memory_companion", + PLUGIN_REPO, ) class MemoryCompanionPlugin(Star): def __init__(self, context: Context, config: dict[str, Any]): @@ -61,7 +59,7 @@ class MemoryCompanionPlugin(Star): _ACTIVE_BRIDGE = self.memory_companion if self.service.config.bool("private_companion_bridge.enabled", True) else None self._register_page_api_if_available() - logger.info("[MemoryCompanion] 我会牢牢记住你 已启动,数据目录=%s", self.service.data_dir) + logger.info("[MemoryCompanionOps] 我会牢牢记住你・运维记忆 已启动,数据目录=%s", self.service.data_dir) def _register_page_api_if_available(self) -> None: if not hasattr(self.context, "register_web_api"): @@ -316,4 +314,4 @@ class MemoryCompanionPlugin(Star): if _ACTIVE_BRIDGE is self.memory_companion: _ACTIVE_BRIDGE = None await self.service.aclose() - logger.info("[MemoryCompanion] 我会牢牢记住你 已停止") + logger.info("[MemoryCompanionOps] 我会牢牢记住你・运维记忆 已停止") diff --git a/metadata.yaml b/metadata.yaml index 689d0f5..62e38e6 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -1,11 +1,11 @@ -name: astrbot_plugin_memory_companion -display_name: 我会牢牢记住你 +name: astrbot_plugin_memory_companion_ops +display_name: 我会牢牢记住你・运维记忆 author: menglimi author_url: https://github.com/menglimi -version: 1.6.2 -description: 我会牢牢记住你是面向 AstrBot 陪伴体系的记忆陪伴中枢。它统一管理长期记忆、历史对话整理、群聊连续对话记忆、主链注入、权限边界、知识图谱、陪伴插件桥接、自然衰减、可移植数据和运行诊断。 +version: 1.6.2-ops.1 +description: 我会牢牢记住你・运维记忆是面向专用 AstrBot VM 运维平台的记忆与项目连续性中枢。它统一管理长期记忆、历史对话整理、群聊连续对话记忆、主链注入、权限边界、知识图谱、陪伴插件桥接、自然衰减、可移植数据和运行诊断。 desc: 为 AstrBot 提供主链记忆注入、历史聊天整理导入、连续对话记忆、陪伴插件协同、主动记忆/回忆工具、知识图谱、权限边界、自我时间线、自然衰减、迁移导出和成本诊断。 -repo: https://github.com/menglimi/astrbot_plugin_memory_companion +repo: https://forgejo.yokiirobw.top:55443/YokiiroBW/astrbot_plugin_memory_companion_ops category: AI 增强 tags: - 长期记忆 @@ -18,4 +18,5 @@ tags: icon: logo.png support_platforms: - aiocqhttp + - qq_official astrbot_version: ">=4.22.0" diff --git a/page_api.py b/page_api.py index 15b1c5f..08fa062 100644 --- a/page_api.py +++ b/page_api.py @@ -26,7 +26,10 @@ except ImportError: from core.identity import normalize_session_context_fields from core.models import SessionContext, clean_text -PLUGIN_NAME = "astrbot_plugin_memory_companion" +try: + from .plugin_identity import PLUGIN_NAME, PRIVATE_COMPANION_PLUGIN_NAMES +except ImportError: + from plugin_identity import PLUGIN_NAME, PRIVATE_COMPANION_PLUGIN_NAMES PAGE_API_PREFIXES = (f"/{PLUGIN_NAME}/page",) logger = logging.getLogger("MemoryCompanion.PageAPI") @@ -1185,34 +1188,35 @@ class PluginPageApi: return {"error": "photo_not_found", "status": 404} def _private_companion_status(self) -> dict[str, Any]: - for module_name in ( - "data.plugins.astrbot_plugin_private_companion.main", - "astrbot_plugin_private_companion.main", - ): - module = sys.modules.get(module_name) - if module is None: - continue - getter = getattr(module, "get_private_companion_api", None) - if not callable(getter): - continue - try: - api = getter() - except Exception: - api = None - if api is None: - continue - plugin = getattr(api, "_plugin", None) - return { - "available": True, - "plugin_name": "astrbot_plugin_private_companion", - "daily_plan_enabled": bool(getattr(plugin, "enable_daily_plan", False)) if plugin else False, - "detail_enabled": bool(getattr(plugin, "enable_detail_enhancement", False)) if plugin else False, - "plugin": plugin, - } + for plugin_name in PRIVATE_COMPANION_PLUGIN_NAMES: + for module_name in ( + f"data.plugins.{plugin_name}.main", + f"{plugin_name}.main", + ): + module = sys.modules.get(module_name) + if module is None: + continue + getter = getattr(module, "get_private_companion_api", None) + if not callable(getter): + continue + try: + api = getter() + except Exception: + api = None + if api is None: + continue + plugin = getattr(api, "_plugin", None) + return { + "available": True, + "plugin_name": plugin_name, + "daily_plan_enabled": bool(getattr(plugin, "enable_daily_plan", False)) if plugin else False, + "detail_enabled": bool(getattr(plugin, "enable_detail_enhancement", False)) if plugin else False, + "plugin": plugin, + } return { "available": False, - "plugin_name": "astrbot_plugin_private_companion", - "reason": "未检测到已加载的主动陪伴插件", + "plugin_name": PRIVATE_COMPANION_PLUGIN_NAMES[0], + "reason": "未检测到已加载的运维人格插件", } @staticmethod diff --git a/plugin_identity.py b/plugin_identity.py new file mode 100644 index 0000000..c1a89e6 --- /dev/null +++ b/plugin_identity.py @@ -0,0 +1,10 @@ +from __future__ import annotations + +PLUGIN_NAME = "astrbot_plugin_memory_companion_ops" +PLUGIN_DISPLAY_NAME = "我会牢牢记住你・运维记忆" +PLUGIN_VERSION = "1.6.2-ops.1" +PLUGIN_REPO = "https://forgejo.yokiirobw.top:55443/YokiiroBW/astrbot_plugin_memory_companion_ops" +PRIVATE_COMPANION_PLUGIN_NAMES = ( + "astrbot_plugin_private_companion_ops", + "astrbot_plugin_private_companion", +) diff --git a/tests/test_archive_contract.py b/tests/test_archive_contract.py index 7c859b9..be7be6d 100644 --- a/tests/test_archive_contract.py +++ b/tests/test_archive_contract.py @@ -6,7 +6,7 @@ from core.visibility import VisibilityPolicy def test_archive_capabilities_use_stable_contract(): payload = archive_capabilities() assert payload["source_name"] == "memory_companion" - assert payload["source_version"] == "1.6.2" + assert payload["source_version"] == "1.6.2-ops.1" assert payload["archive_api_version"] == "1.0" assert payload["memory_write_available"] is False assert payload["available"] is True