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/daily_quest.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.

"""
Memora v4.0 - Daily Quest System

每日任务系统

支持:
- 4 个通用基础任务
- 05:00 自动刷新
- 自动检测任务完成
- 全部完成额外奖励
- 每日推送通知(可选)

Author: 枢衡
Date: 2026-03-20
Version: 5.0.0
"""

import json
import os
from typing import Dict, List, Optional
from pathlib import Path
from datetime import datetime, timedelta
import sys

# 添加父目录到路径
sys.path.insert(0, str(Path(__file__).parent))

try:
    from .exp_tracker import EXPTracker
except ImportError:
    from exp_tracker import EXPTracker


class DailyQuestSystem:
    """每日任务系统"""
    
    # 4 个通用基础任务配置
    QUEST_TEMPLATES = {
        'write_fact': {
            'id': 'write_fact',
            'title': '写 1 条事实',
            'description': '记录今天的工作或学习(episodic 或 semantic)',
            'dimension': 'understanding',
            'exp_reward': 1,
            'target_count': 1,
            'check_method': 'count_facts',
            'icon': '📝'
        },
        'memory_search': {
            'id': 'memory_search',
            'title': '搜索 1 次记忆',
            'description': '主动检索已有知识(使用 memory_search)',
            'dimension': 'application',
            'exp_reward': 2,
            'target_count': 1,
            'check_method': 'count_searches',
            'icon': '🔍'
        },
        'complete_task': {
            'id': 'complete_task',
            'title': '完成 1 个任务',
            'description': '完成任何工作任务(Vega 任务、代码任务等)',
            'dimension': 'application',
            'exp_reward': 30,
            'target_count': 1,
            'check_method': 'count_completed_tasks',
            'icon': '✅'
        },
        'collaboration': {
            'id': 'collaboration',
            'title': '参与 1 次协作',
            'description': '写入 shared/ 或读取他人知识,或协助他人',
            'dimension': 'collaboration',
            'exp_reward': 15,
            'target_count': 1,
            'check_method': 'count_collaboration',
            'icon': '💬'
        }
    }
    
    # 全部完成额外奖励
    ALL_COMPLETE_BONUS = 50
    
    def __init__(self, agent_name: str, facts_base: str = None):
        """
        初始化每日任务系统
        
        Args:
            agent_name: Agent 名称
            facts_base: facts 基础路径
        """
        self.agent_name = agent_name
        if facts_base is None:
            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
            facts_base = str(get_config().facts_base)
        self.facts_base = Path(facts_base)
        self.agent_dir = self.facts_base / agent_name
        self.quests_dir = self.agent_dir / 'daily_quests'
        
        # 确保目录存在
        self.quests_dir.mkdir(parents=True, exist_ok=True)
        
        # 初始化 EXP 追踪器
        self.exp_tracker = EXPTracker(agent_name, facts_base)
    
    def get_today_quests(self, date: Optional[str] = None) -> Dict:
        """
        获取今日任务列表
        
        Args:
            date: 日期(可选),默认今天
        
        Returns:
            任务状态字典
        """
        if date is None:
            date = datetime.now().strftime('%Y-%m-%d')
        
        quest_file = self.quests_dir / f'{date}.json'
        
        if quest_file.exists():
            # 读取现有任务
            with open(quest_file, 'r', encoding='utf-8') as f:
                return json.load(f)
        else:
            # 生成新任务
            return self._generate_quests(date)
    
    def _generate_quests(self, date: str) -> Dict:
        """生成新的任务列表"""
        quests_data = {
            'date': date,
            'agent': self.agent_name,
            'generated_at': datetime.now().isoformat(),
            'quests': [],
            'total_exp_available': 0,
            'total_exp_earned': 0,
            'all_completed': False
        }
        
        # 添加 4 个基础任务
        for quest_id, template in self.QUEST_TEMPLATES.items():
            quest = {
                **template,
                'current_count': 0,
                'completed': False,
                'completed_at': None
            }
            quests_data['quests'].append(quest)
            quests_data['total_exp_available'] += quest['exp_reward']
        
        # 保存
        quest_file = self.quests_dir / f'{date}.json'
        with open(quest_file, 'w', encoding='utf-8') as f:
            json.dump(quests_data, f, ensure_ascii=False, indent=2)
        
        return quests_data
    
    def check_quest_progress(self, date: Optional[str] = None) -> Dict:
        """
        检查任务进度
        
        Args:
            date: 日期(可选)
        
        Returns:
            更新后的任务状态
        """
        if date is None:
            date = datetime.now().strftime('%Y-%m-%d')
        
        quests_data = self.get_today_quests(date)
        
        # 检查每个任务的进度
        for quest in quests_data['quests']:
            if quest['completed']:
                continue  # 已完成的任务跳过
            
            # 根据 check_method 检查进度
            method = quest.get('check_method', '')
            
            if method == 'count_facts':
                count = self._count_facts_today(date)
                quest['current_count'] = count
            
            elif method == 'count_searches':
                count = self._count_searches_today(date)
                quest['current_count'] = count
            
            elif method == 'count_completed_tasks':
                count = self._count_completed_tasks_today(date)
                quest['current_count'] = count
            
            elif method == 'count_collaboration':
                count = self._count_collaboration_today(date)
                quest['current_count'] = count
            
            # 检查是否完成
            if quest['current_count'] >= quest['target_count']:
                quest['completed'] = True
                quest['completed_at'] = datetime.now().isoformat()
                
                # 发放 EXP 奖励
                self._award_exp(quest, date)
        
        # 检查是否全部完成
        all_completed = all(q['completed'] for q in quests_data['quests'])
        
        if all_completed and not quests_data['all_completed']:
            # 发放额外奖励
            quests_data['all_completed'] = True
            self._award_bonus(date)
        
        # 更新总 EXP
        quests_data['total_exp_earned'] = sum(
            q['exp_reward'] for q in quests_data['quests'] if q['completed']
        )
        if quests_data['all_completed']:
            quests_data['total_exp_earned'] += self.ALL_COMPLETE_BONUS
        
        # 保存更新
        quest_file = self.quests_dir / f'{date}.json'
        with open(quest_file, 'w', encoding='utf-8') as f:
            json.dump(quests_data, f, ensure_ascii=False, indent=2)
        
        return quests_data
    
    def _count_facts_today(self, date: str) -> int:
        """统计今天写的 facts 数量"""
        facts_dir = self.agent_dir / 'facts'
        if not facts_dir.exists():
            return 0
        
        count = 0
        for fact_type in ['episodic', 'semantic']:
            type_dir = facts_dir / fact_type
            if type_dir.exists():
                for fact_file in type_dir.glob(f'*{date}*.md'):
                    count += 1
        
        return count
    
    def _count_searches_today(self, date: str) -> int:
        """统计今天的记忆搜索次数(BUG-017 修复:多源统计)"""
        exp_history = self.exp_tracker.get_exp_history(date, date, 'application')
        # 匹配所有可能的搜索相关 action
        search_actions = (
            'memory_search', 'import_from_sessions',
            'knowledge_reuse', 'search_then_complete_task',
        )
        count = sum(1 for r in exp_history if r.get('action') in search_actions)

        # fallback: 如果没有精确匹配,至少算有 application 维度的 EXP 存在
        if count == 0 and len(exp_history) > 0:
            count = 1  # 有 application 记录就至少算 1 次

        return count
    
    def _count_completed_tasks_today(self, date: str) -> int:
        """统计今天完成的任务数"""
        # 从 exp_history 统计
        exp_history = self.exp_tracker.get_exp_history(date, date)
        return sum(1 for r in exp_history if r.get('action') == 'complete_task')
    
    def _count_collaboration_today(self, date: str) -> int:
        """统计今天的协作次数"""
        # 检查 shared/ 目录
        shared_dir = self.facts_base / 'shared'
        count = 0
        
        if shared_dir.exists():
            for shared_file in shared_dir.glob(f'*{date}*.md'):
                try:
                    content = shared_file.read_text(encoding='utf-8')
                    if self.agent_name in content:
                        count += 1
                except Exception:
                    continue
        
        # 从 exp_history 统计协作行为
        exp_history = self.exp_tracker.get_exp_history(date, date, 'collaboration')
        count += len(exp_history)
        
        return count
    
    def _award_exp(self, quest: Dict, date: str):
        """发放任务 EXP 奖励"""
        dimension = quest['dimension']
        exp = quest['exp_reward']
        
        self.exp_tracker.add_exp(
            dimension=dimension,
            action=f'complete_quest_{quest["id"]}',
            exp=exp,
            details={'quest_id': quest['id'], 'quest_title': quest['title']},
            date=date
        )
    
    def _award_bonus(self, date: str):
        """发放全部完成额外奖励"""
        self.exp_tracker.add_exp(
            dimension='application',  # 额外奖励计入应用维度
            action='all_quests_completed',
            exp=self.ALL_COMPLETE_BONUS,
            details={'bonus': 'all_quests_completed'},
            date=date
        )
    
    def refresh_quests(self, date: Optional[str] = None) -> Dict:
        """
        刷新任务(生成新一天的任务)
        
        Args:
            date: 日期(可选)
        
        Returns:
            新的任务列表
        """
        if date is None:
            date = datetime.now().strftime('%Y-%m-%d')
        
        # 删除旧任务(如果存在)
        quest_file = self.quests_dir / f'{date}.json'
        if quest_file.exists():
            quest_file.unlink()
        
        # 生成新任务
        return self._generate_quests(date)
    
    def get_quest_card(self, date: Optional[str] = None) -> str:
        """
        生成任务卡片(Markdown 格式)
        
        Args:
            date: 日期(可选)
        
        Returns:
            Markdown 格式的任务卡片
        """
        quests_data = self.get_today_quests(date)
        
        lines = []
        lines.append(f"📅 每日任务 — {quests_data['date']}")
        lines.append("")
        lines.append(f"**Agent:** {self.agent_name}")
        lines.append("")
        
        # 任务列表
        for quest in quests_data['quests']:
            icon = quest.get('icon', '⬜')
            status = '✅' if quest['completed'] else '⬜'
            progress = f"{quest['current_count']}/{quest['target_count']}"
            
            lines.append(f"{status} {icon} **{quest['title']}** (+{quest['exp_reward']} EXP)")
            lines.append(f"   {quest['description']}")
            lines.append(f"   进度:{progress}")
            lines.append("")
        
        # 总结
        lines.append("---")
        lines.append("")
        
        earned = quests_data['total_exp_earned']
        available = quests_data['total_exp_available']
        
        if quests_data['all_completed']:
            lines.append(f"🎉 **全部完成!** 获得额外奖励 +{self.ALL_COMPLETE_BONUS} EXP")
        
        lines.append(f"**今日获得:** {earned}/{available} EXP")
        lines.append("")
        
        return '\n'.join(lines)


def main():
    """测试每日任务系统"""
    import sys
    
    if len(sys.argv) < 2:
        print("用法:python3 daily_quest.py <Agent 名称> [命令]")
        print("命令:status, refresh, check")
        sys.exit(1)
    
    agent_name = sys.argv[1]
    quest_system = DailyQuestSystem(agent_name)
    
    command = sys.argv[2] if len(sys.argv) > 2 else 'status'
    
    if command == 'status':
        # 显示今日任务
        card = quest_system.get_quest_card()
        print(card)
    
    elif command == 'refresh':
        # 刷新任务
        quests = quest_system.refresh_quests()
        print(f"✅ 任务已刷新({quests['date']})")
        print(quest_system.get_quest_card())
    
    elif command == 'check':
        # 检查进度
        quests = quest_system.check_quest_progress()
        print(f"✅ 进度已更新")
        print(quest_system.get_quest_card())
    
    else:
        print(f"未知命令:{command}")


if __name__ == '__main__':
    main()
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