Skip to content

LeoYeAI/agent-master-skills / skills/anima-aios

anima-aios

Verified

An AI Agent cognitive growth system built on the native OpenClaw architecture. It provides agents with persistent memory management, visual intimacy progression, a 5-dimensional cognitive profile, gamified daily quests, team leaderboards, and a 5-layer memory architecture with Knowledge Palace, Pyramid thinking, and Ebbinghaus decay function. 基于 OpenClaw 原生架构的 AI Agent 认知成长体系,为 Agent 提供五层记忆架构、知识宫殿、金字塔知识组织、记忆衰减函数、LLM 智能处理、永久化记忆管理、可视化亲密度成长、五维认知画像、游戏化每日任务和团队排行榜。

FileKindSize
CHANGELOG.mdmarkdown2.4 KB
CONTRIBUTING.mdmarkdown3.3 KB
PLAN_v6.2.3.mdmarkdown5.3 KB
README.mdmarkdown5.1 KB
README_CN.mdmarkdown7.2 KB
RELEASE_v6.2.1.mdmarkdown3.5 KB
RELEASE_v6.2.2.mdmarkdown5.0 KB
RELEASE_v6.2.3.mdmarkdown4.0 KB
SECURITY.mdmarkdown2.6 KB
SECURITY_RESPONSE.mdmarkdown5.9 KB
SKILL.mdskill md23.5 KB
__init__.pyscript71 B
_meta.jsonconfig453 B
anima_doctor.pyscript26.4 KB
anima_tools.pyscript37.2 KB
config/__init__.pyscript0 B
config/agents/template.jsonconfig683 B
config/anima_config.template.jsonconfig1.5 KB
config/config_loader.pyscript9.3 KB
config/organization_config.jsonconfig1.2 KB
config/path_config.pyscript7.2 KB
core/__init__.pyscript1.5 KB
core/agent_resolver.pyscript5.1 KB
core/cognitive_profile.pyscript13.5 KB
core/daily_quest.pyscript13.9 KB
core/decay_function.pyscript6.8 KB
core/dimension_calculator.pyscript23.0 KB
core/distill_engine.pyscript18.8 KB
core/exp_tracker.pyscript15.0 KB
core/fact_store.pyscript9.5 KB
core/level_system.pyscript9.1 KB
core/memory_sync.pyscript6.1 KB
core/memory_watcher.pyscript14.9 KB
core/native_importer.pyscript31.0 KB
core/normalization_engine.pyscript11.7 KB
core/palace_classifier.pyscript12.2 KB
core/palace_index.pyscript10.7 KB
core/profile_card.pyscript9.6 KB
core/pyramid_engine.pyscript10.3 KB
core/session_scanner.pyscript12.7 KB
core/team_scanner.pyscript9.7 KB
docs/ARCHITECTURE_PRINCIPLES.mdmarkdown2.8 KB
docs/EXAMPLES.mdmarkdown2.1 KB
docs/USAGE.mdmarkdown2.8 KB
docs/session-jsonl-schema.mdmarkdown1.8 KB
health/__init__.pyscript16.9 KB
post-install.shscript2.2 KB
scripts/refresh-quests.shscript511 B
scripts/show-progress.shscript450 B
scripts/sync-memory.shscript1.4 KB
tests/__init__.pyscript627 B
tests/test_daily_quest.pyscript9.0 KB
tests/test_exp_tracker.pyscript8.6 KB
tests/test_integration_v6.pyscript8.9 KB
tests/test_normalization.pyscript8.2 KB

core/memory_sync.py

View on GitHub
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright 2026 Anima-AIOS Contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Anima-AIOS - 记忆同步模块

第二层:启动同步(兜底机制)
- Anima 启动时检查并补全缺失的记忆
- 从 Workspace 同步到画像目录
"""

import os
import shutil
from pathlib import Path
from datetime import datetime


class MemorySync:
    """记忆同步器"""
    
    def __init__(self, agent_name: str):
        """
        初始化同步器
        
        Args:
            agent_name: Agent 名称
        """
        self.agent_name = agent_name
        # 自动检测 workspace 路径,不硬编码
        workspace_name = os.getenv("ANIMA_WORKSPACE_NAME", "")
        if not workspace_name:
            # 自动扫描:查找 ~/.openclaw/workspace-*/memory/ 目录
            openclaw_dir = Path(os.path.expanduser("~/.openclaw"))
            candidates = list(openclaw_dir.glob("workspace-*/memory"))
            if candidates:
                self.workspace_mem = candidates[0]
            else:
                self.workspace_mem = openclaw_dir / "workspace" / "memory"
        else:
            self.workspace_mem = Path(os.path.expanduser(f"~/.openclaw/workspace-{workspace_name}/memory"))
        # 获取 facts_base(支持环境变量和配置文件)
        try:
            from ..config.path_config import get_config
        except ImportError:
            import sys as _s
            _s.path.insert(0, str(__import__("pathlib").Path(__file__).parent.parent / "config"))
            from path_config import get_config
        _cfg = get_config()
        self.portrait_mem = _cfg.facts_base / agent_name / "memory"
        
        # 确保画像目录存在
        self.portrait_mem.mkdir(parents=True, exist_ok=True)
    
    def sync_on_startup(self):
        """
        启动时同步记忆
        
        Returns:
            dict: 同步统计
        """
        stats = {
            'synced': 0,
            'skipped': 0,
            'errors': 0
        }
        
        if not self.workspace_mem.exists():
            print(f"⚠️  Workspace 记忆目录不存在:{self.workspace_mem}")
            return stats
        
        # 同步所有记忆文件
        for mem_file in self.workspace_mem.glob("*.md"):
            if mem_file.name.startswith('.'):
                continue
            
            try:
                dest = self.portrait_mem / mem_file.name
                
                # 如果画像目录没有该文件,则复制
                if not dest.exists():
                    shutil.copy2(mem_file, dest)
                    print(f"✅ 同步记忆:{mem_file.name}")
                    stats['synced'] += 1
                else:
                    # 文件已存在,跳过
                    stats['skipped'] += 1
            except Exception as e:
                print(f"❌ 同步失败 {mem_file.name}: {e}")
                stats['errors'] += 1
        
        return stats
    
    def sync_today(self):
        """
        同步今日记忆
        
        Returns:
            bool: 是否成功
        """
        today = datetime.now().strftime("%Y-%m-%d")
        workspace_today = self.workspace_mem / f"{today}.md"
        portrait_today = self.portrait_mem / f"{today}.md"
        
        if not workspace_today.exists():
            print(f"⚠️  今日记忆不存在:{workspace_today}")
            return False
        
        try:
            # 复制今日记忆
            shutil.copy2(workspace_today, portrait_today)
            print(f"✅ 今日记忆已同步:{today}.md")
            return True
        except Exception as e:
            print(f"❌ 同步今日记忆失败:{e}")
            return False
    
    def check_sync_status(self):
        """
        检查同步状态
        
        Returns:
            dict: 同步状态
        """
        status = {
            'workspace_exists': self.workspace_mem.exists(),
            'portrait_exists': self.portrait_mem.exists(),
            'workspace_files': 0,
            'portrait_files': 0,
            'missing_files': []
        }
        
        if self.workspace_mem.exists():
            status['workspace_files'] = len(list(self.workspace_mem.glob("*.md")))
        
        if self.portrait_mem.exists():
            status['portrait_files'] = len(list(self.portrait_mem.glob("*.md")))
            
            # 检查缺失的文件
            for mem_file in self.workspace_mem.glob("*.md"):
                if mem_file.name.startswith('.'):
                    continue
                
                dest = self.portrait_mem / mem_file.name
                if not dest.exists():
                    status['missing_files'].append(mem_file.name)
        
        return status


def sync_memory_on_startup(agent_name: str):
    """
    Anima 启动时同步记忆
    
    Args:
        agent_name: Agent 名称
    """
    print("=" * 60)
    print("  🔄 同步记忆(启动时)")
    print("=" * 60)
    
    sync = MemorySync(agent_name)
    stats = sync.sync_on_startup()
    
    print()
    print(f"同步完成:")
    print(f"  - 已同步:{stats['synced']} 个文件")
    print(f"  - 已跳过:{stats['skipped']} 个文件")
    print(f"  - 错误:{stats['errors']} 个")
    print()


if __name__ == "__main__":
    import sys
    
    if len(sys.argv) > 1:
        agent_name = sys.argv[1]
    else:
        try:
            from .agent_resolver import resolve_agent_name
        except ImportError:
            from agent_resolver import resolve_agent_name
        agent_name = resolve_agent_name()
    
    sync_memory_on_startup(agent_name)
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: 472kUpdated Claude CodeCodexVerifiedInstall
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: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
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 availableStars: 322kUpdated Claude CodeCodexVerifiedInstall