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

tests/test_exp_tracker.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 v5.0 - EXP Tracker Tests

测试 EXP 追踪器的核心功能
"""

import sys
import unittest
import json
import os
import tempfile
from pathlib import Path
from datetime import datetime, timedelta

# 添加核心模块路径
sys.path.insert(0, str(Path(__file__).parent.parent / 'core'))

from exp_tracker import EXPTracker


class TestEXPTracker(unittest.TestCase):
    """EXP 追踪器测试"""
    
    def setUp(self):
        """测试前准备 - 创建临时目录"""
        self.temp_dir = tempfile.mkdtemp()
        self.agent_name = "TestAgent"
        self.tracker = EXPTracker(self.agent_name, self.temp_dir)
    
    def tearDown(self):
        """测试后清理 - 删除临时目录"""
        import shutil
        shutil.rmtree(self.temp_dir, ignore_errors=True)
    
    def test_add_exp_success(self):
        """测试成功添加 EXP"""
        success, message = self.tracker.add_exp(
            dimension='understanding',
            action='write_semantic_fact',
            exp=2,
            details={'fact_id': 'test_001'}
        )
        
        self.assertTrue(success, f"添加 EXP 失败:{message}")
        self.assertIn("添加 EXP", message)
    
    def test_add_exp_with_quality_multiplier(self):
        """测试带质量系数的 EXP 添加"""
        success, message = self.tracker.add_exp(
            dimension='understanding',
            action='write_semantic_fact',
            exp=2,
            details={'fact_id': 'test_002'},
            quality_multiplier=1.5
        )
        
        self.assertTrue(success)
        
        # 验证实际添加的 EXP 是 2 * 1.5 = 3
        history = self.tracker.get_exp_history()
        self.assertEqual(len(history), 1)
        self.assertAlmostEqual(history[0]['exp'], 3.0, places=2)
    
    def test_daily_exp_limit(self):
        """测试每日 EXP 上限"""
        dimension = 'understanding'
        limit = self.tracker.DAILY_EXP_LIMITS[dimension]  # 50
        
        # 添加接近上限的 EXP
        success1, _ = self.tracker.add_exp(
            dimension=dimension,
            action='test_action_1',
            exp=limit - 5,  # 45
            details={'test': 1}
        )
        self.assertTrue(success1)
        
        # 再次添加会超过上限
        success2, message = self.tracker.add_exp(
            dimension=dimension,
            action='test_action_2',
            exp=10,  # 会超过 50
            details={'test': 2}
        )
        
        # 应该只添加到上限
        self.assertTrue(success2)  # 部分成功
        self.assertIn("上限", message)
        
        # 验证总 EXP 不超过上限
        total = self.tracker.get_total_exp()
        self.assertLessEqual(total, limit + 0.1)  # 允许小数误差
    
    def test_exp_history_retrieval(self):
        """测试 EXP 历史记录检索"""
        today = datetime.now().strftime('%Y-%m-%d')
        yesterday = (datetime.now() - timedelta(days=1)).strftime('%Y-%m-%d')
        
        # 添加两条记录
        self.tracker.add_exp('understanding', 'action1', 2, {'test': 1}, today)
        self.tracker.add_exp('application', 'action2', 3, {'test': 2}, today)
        self.tracker.add_exp('understanding', 'action3', 4, {'test': 3}, yesterday)
        
        # 获取今天的所有记录
        today_history = self.tracker.get_exp_history(today, today)
        self.assertEqual(len(today_history), 2)
        
        # 获取特定维度的记录
        understanding_history = self.tracker.get_exp_history(today, today, 'understanding')
        self.assertEqual(len(understanding_history), 1)
        self.assertEqual(understanding_history[0]['exp'], 2)
    
    def test_total_exp_calculation(self):
        """测试总 EXP 计算"""
        today = datetime.now().strftime('%Y-%m-%d')
        
        # 添加多条记录
        self.tracker.add_exp('understanding', 'action1', 2, {}, today)
        self.tracker.add_exp('application', 'action2', 3, {}, today)
        self.tracker.add_exp('creation', 'action3', 5, {}, today)
        
        # 计算总 EXP
        total = self.tracker.get_total_exp(today, today)
        self.assertEqual(total, 10)
    
    def test_daily_summary(self):
        """测试每日摘要"""
        today = datetime.now().strftime('%Y-%m-%d')
        
        # 添加 EXP
        self.tracker.add_exp('understanding', 'action1', 2, {}, today)
        self.tracker.add_exp('application', 'action2', 3, {}, today)
        
        # 获取摘要
        summary = self.tracker.get_daily_summary(today)
        
        self.assertEqual(summary['date'], today)
        self.assertAlmostEqual(summary['total'], 5, places=2)
        self.assertIn('understanding', summary['dimensions'])
        self.assertIn('application', summary['dimensions'])
    
    def test_quality_multiplier_calculation(self):
        """测试质量系数计算"""
        # 短内容(<50 字)
        short_content = "A" * 30
        multiplier = self.tracker.calculate_quality_multiplier(short_content)
        self.assertEqual(multiplier, 0.3)
        
        # 正常内容(50-200 字)
        normal_content = "B" * 100
        multiplier = self.tracker.calculate_quality_multiplier(normal_content)
        self.assertEqual(multiplier, 1.0)
        
        # 长内容(>200 字)
        long_content = "C" * 300
        multiplier = self.tracker.calculate_quality_multiplier(long_content)
        self.assertEqual(multiplier, 1.5)
    
    def test_duplicate_detection(self):
        """测试重复检测(简化版)"""
        # 重复检测是可选功能,取决于实现细节
        # 这里只测试接口存在
        details = {'fact_id': 'unique_123'}
        is_duplicate = self.tracker.check_duplicate('write_fact', details)
        self.assertIsInstance(is_duplicate, bool)
    
    def test_exp_report_export(self):
        """测试 EXP 报告导出"""
        today = datetime.now().strftime('%Y-%m-%d')
        
        # 添加一些 EXP
        self.tracker.add_exp('understanding', 'action1', 2, {}, today)
        self.tracker.add_exp('application', 'action2', 3, {}, today)
        
        # 导出报告
        output_path = Path(self.temp_dir) / 'test_report.json'
        result_path = self.tracker.export_exp_report(str(output_path), today, today)
        
        # 验证文件存在
        self.assertTrue(os.path.exists(result_path))
        
        # 验证内容
        with open(result_path, 'r', encoding='utf-8') as f:
            report = json.load(f)
        
        self.assertEqual(report['agent'], self.agent_name)
        self.assertEqual(report['total_exp'], 5)
        self.assertEqual(report['record_count'], 2)


class TestEXPTrackerPersistence(unittest.TestCase):
    """EXP 追踪器持久化测试"""
    
    def setUp(self):
        self.temp_dir = tempfile.mkdtemp()
        self.agent_name = "PersistTest"
        self.tracker = EXPTracker(self.agent_name, self.temp_dir)
    
    def tearDown(self):
        import shutil
        shutil.rmtree(self.temp_dir, ignore_errors=True)
    
    def test_data_persistence(self):
        """测试数据持久化"""
        today = datetime.now().strftime('%Y-%m-%d')
        
        # 添加 EXP
        self.tracker.add_exp('understanding', 'action1', 2, {'test': 1}, today)
        
        # 创建新的 tracker 实例(模拟重启)
        tracker2 = EXPTracker(self.agent_name, self.temp_dir)
        
        # 验证数据还在
        history = tracker2.get_exp_history(today, today)
        self.assertEqual(len(history), 1)
        self.assertEqual(history[0]['action'], 'action1')


def run_tests():
    """运行所有测试"""
    loader = unittest.TestLoader()
    suite = unittest.TestSuite()
    
    suite.addTests(loader.loadTestsFromTestCase(TestEXPTracker))
    suite.addTests(loader.loadTestsFromTestCase(TestEXPTrackerPersistence))
    
    runner = unittest.TextTestRunner(verbosity=2)
    result = runner.run(suite)
    
    return result.wasSuccessful()


if __name__ == '__main__':
    success = run_tests()
    sys.exit(0 if success else 1)
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