youclaw 4.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- youclaw-4.6.0/LICENSE +21 -0
- youclaw-4.6.0/MANIFEST.in +8 -0
- youclaw-4.6.0/PKG-INFO +128 -0
- youclaw-4.6.0/README.md +106 -0
- youclaw-4.6.0/pyproject.toml +43 -0
- youclaw-4.6.0/setup.cfg +4 -0
- youclaw-4.6.0/src/youclaw/__init__.py +24 -0
- youclaw-4.6.0/src/youclaw/bot.py +185 -0
- youclaw-4.6.0/src/youclaw/cli.py +469 -0
- youclaw-4.6.0/src/youclaw/commands.py +151 -0
- youclaw-4.6.0/src/youclaw/config.py +170 -0
- youclaw-4.6.0/src/youclaw/core_skills.py +210 -0
- youclaw-4.6.0/src/youclaw/dashboard.py +1347 -0
- youclaw-4.6.0/src/youclaw/discord_handler.py +187 -0
- youclaw-4.6.0/src/youclaw/env_manager.py +61 -0
- youclaw-4.6.0/src/youclaw/main.py +273 -0
- youclaw-4.6.0/src/youclaw/memory_manager.py +440 -0
- youclaw-4.6.0/src/youclaw/ollama_client.py +486 -0
- youclaw-4.6.0/src/youclaw/personality_manager.py +42 -0
- youclaw-4.6.0/src/youclaw/scheduler_manager.py +226 -0
- youclaw-4.6.0/src/youclaw/search_client.py +66 -0
- youclaw-4.6.0/src/youclaw/skills_manager.py +127 -0
- youclaw-4.6.0/src/youclaw/telegram_handler.py +181 -0
- youclaw-4.6.0/src/youclaw/vector_manager.py +94 -0
- youclaw-4.6.0/src/youclaw.egg-info/PKG-INFO +128 -0
- youclaw-4.6.0/src/youclaw.egg-info/SOURCES.txt +28 -0
- youclaw-4.6.0/src/youclaw.egg-info/dependency_links.txt +1 -0
- youclaw-4.6.0/src/youclaw.egg-info/entry_points.txt +2 -0
- youclaw-4.6.0/src/youclaw.egg-info/requires.txt +10 -0
- youclaw-4.6.0/src/youclaw.egg-info/top_level.txt +1 -0
youclaw-4.6.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Imran
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
youclaw-4.6.0/PKG-INFO
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: youclaw
|
|
3
|
+
Version: 4.6.0
|
|
4
|
+
Summary: Your Personal AI Assistant - Universal Neural Core
|
|
5
|
+
Author-email: Imran <imran@example.com>
|
|
6
|
+
Classifier: Programming Language :: Python :: 3
|
|
7
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: aiosqlite
|
|
13
|
+
Requires-Dist: aiohttp
|
|
14
|
+
Requires-Dist: aiohttp-jinja2
|
|
15
|
+
Requires-Dist: jinja2
|
|
16
|
+
Requires-Dist: python-dotenv
|
|
17
|
+
Requires-Dist: apscheduler
|
|
18
|
+
Requires-Dist: python-telegram-bot
|
|
19
|
+
Requires-Dist: discord.py
|
|
20
|
+
Requires-Dist: httpx
|
|
21
|
+
Requires-Dist: beautifulsoup4
|
|
22
|
+
|
|
23
|
+
# 🦞 YouClaw - Your Personal AI Assistant
|
|
24
|
+
|
|
25
|
+
**YouClaw** is a powerful, self-hosted AI assistant that connects to Telegram, Discord, and a beautiful web dashboard. Built with privacy in mind, all your data stays on your machine.
|
|
26
|
+
|
|
27
|
+
## ✨ Features
|
|
28
|
+
|
|
29
|
+
- 🤖 **Multi-Platform**: Telegram, Discord, and Web Dashboard
|
|
30
|
+
- 🧠 **Semantic Memory**: Remembers context using vector embeddings
|
|
31
|
+
- ⚡ **AI Cron Jobs**: Schedule recurring AI-powered tasks
|
|
32
|
+
- 🔍 **Real-Time Search**: Integrated web search for up-to-date information
|
|
33
|
+
- 📧 **Email Integration**: Send and check emails via AI commands
|
|
34
|
+
- 🎭 **Multiple Personalities**: Switch between different AI personas
|
|
35
|
+
- 🛡️ **Admin Controls**: Full control over your personal instance
|
|
36
|
+
- 📦 **Self-Contained**: No external API keys required (uses local Ollama)
|
|
37
|
+
|
|
38
|
+
## 🚀 Quick Start
|
|
39
|
+
|
|
40
|
+
### Prerequisites
|
|
41
|
+
|
|
42
|
+
- Python 3.10+
|
|
43
|
+
- [Ollama](https://ollama.ai) installed and running locally
|
|
44
|
+
|
|
45
|
+
### Installation
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install youclaw
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### First Run
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
youclaw start
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
This will launch the **Neural Wizard** - an interactive setup that guides you through:
|
|
58
|
+
- Telegram bot token configuration
|
|
59
|
+
- Discord bot token configuration
|
|
60
|
+
- Search engine URL (optional)
|
|
61
|
+
- Email credentials (optional)
|
|
62
|
+
|
|
63
|
+
You can skip any step and configure it later via the dashboard.
|
|
64
|
+
|
|
65
|
+
### Access Dashboard
|
|
66
|
+
|
|
67
|
+
After setup, access your Mission Control at:
|
|
68
|
+
```
|
|
69
|
+
http://localhost:8080
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 📖 Usage
|
|
73
|
+
|
|
74
|
+
### CLI Commands
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
youclaw start # Start YouClaw (runs wizard if unconfigured)
|
|
78
|
+
youclaw check # Health check
|
|
79
|
+
youclaw dashboard # Start dashboard only
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Creating Your First Admin Account
|
|
83
|
+
|
|
84
|
+
1. Navigate to `http://localhost:8080`
|
|
85
|
+
2. Click "Register"
|
|
86
|
+
3. Create your account (first user is automatically admin)
|
|
87
|
+
4. Access the ROOT PROTOCOLS panel at the bottom
|
|
88
|
+
|
|
89
|
+
## 🔧 Configuration
|
|
90
|
+
|
|
91
|
+
YouClaw stores configuration in `.env` and uses SQLite for data persistence.
|
|
92
|
+
|
|
93
|
+
### Environment Variables
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
OLLAMA_HOST=http://localhost:11434
|
|
97
|
+
OLLAMA_MODEL=qwen2.5:1.5b-instruct
|
|
98
|
+
TELEGRAM_BOT_TOKEN=your_token_here
|
|
99
|
+
DISCORD_BOT_TOKEN=your_token_here
|
|
100
|
+
SEARCH_ENGINE_URL=http://your-search-engine/search
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## 🛡️ Security
|
|
104
|
+
|
|
105
|
+
- **Universal Admin**: Every user on your personal clone has full admin rights
|
|
106
|
+
- **Local-First**: All data stays on your machine
|
|
107
|
+
- **Token-Based Auth**: Secure session management for the dashboard
|
|
108
|
+
- **No Cloud Dependencies**: Runs entirely offline (except for bot platforms)
|
|
109
|
+
|
|
110
|
+
## 📝 License
|
|
111
|
+
|
|
112
|
+
MIT License - See LICENSE file for details
|
|
113
|
+
|
|
114
|
+
## 🤝 Contributing
|
|
115
|
+
|
|
116
|
+
Contributions are welcome! This is an open-source personal AI assistant project.
|
|
117
|
+
|
|
118
|
+
## 🐛 Issues
|
|
119
|
+
|
|
120
|
+
Report issues on GitHub: [Your Repository URL]
|
|
121
|
+
|
|
122
|
+
## 💬 Community
|
|
123
|
+
|
|
124
|
+
Join the discussion: [Your Community Link]
|
|
125
|
+
|
|
126
|
+
---
|
|
127
|
+
|
|
128
|
+
**Made with 🦞 by the YouClaw Community**
|
youclaw-4.6.0/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# 🦞 YouClaw - Your Personal AI Assistant
|
|
2
|
+
|
|
3
|
+
**YouClaw** is a powerful, self-hosted AI assistant that connects to Telegram, Discord, and a beautiful web dashboard. Built with privacy in mind, all your data stays on your machine.
|
|
4
|
+
|
|
5
|
+
## ✨ Features
|
|
6
|
+
|
|
7
|
+
- 🤖 **Multi-Platform**: Telegram, Discord, and Web Dashboard
|
|
8
|
+
- 🧠 **Semantic Memory**: Remembers context using vector embeddings
|
|
9
|
+
- ⚡ **AI Cron Jobs**: Schedule recurring AI-powered tasks
|
|
10
|
+
- 🔍 **Real-Time Search**: Integrated web search for up-to-date information
|
|
11
|
+
- 📧 **Email Integration**: Send and check emails via AI commands
|
|
12
|
+
- 🎭 **Multiple Personalities**: Switch between different AI personas
|
|
13
|
+
- 🛡️ **Admin Controls**: Full control over your personal instance
|
|
14
|
+
- 📦 **Self-Contained**: No external API keys required (uses local Ollama)
|
|
15
|
+
|
|
16
|
+
## 🚀 Quick Start
|
|
17
|
+
|
|
18
|
+
### Prerequisites
|
|
19
|
+
|
|
20
|
+
- Python 3.10+
|
|
21
|
+
- [Ollama](https://ollama.ai) installed and running locally
|
|
22
|
+
|
|
23
|
+
### Installation
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install youclaw
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### First Run
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
youclaw start
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
This will launch the **Neural Wizard** - an interactive setup that guides you through:
|
|
36
|
+
- Telegram bot token configuration
|
|
37
|
+
- Discord bot token configuration
|
|
38
|
+
- Search engine URL (optional)
|
|
39
|
+
- Email credentials (optional)
|
|
40
|
+
|
|
41
|
+
You can skip any step and configure it later via the dashboard.
|
|
42
|
+
|
|
43
|
+
### Access Dashboard
|
|
44
|
+
|
|
45
|
+
After setup, access your Mission Control at:
|
|
46
|
+
```
|
|
47
|
+
http://localhost:8080
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 📖 Usage
|
|
51
|
+
|
|
52
|
+
### CLI Commands
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
youclaw start # Start YouClaw (runs wizard if unconfigured)
|
|
56
|
+
youclaw check # Health check
|
|
57
|
+
youclaw dashboard # Start dashboard only
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Creating Your First Admin Account
|
|
61
|
+
|
|
62
|
+
1. Navigate to `http://localhost:8080`
|
|
63
|
+
2. Click "Register"
|
|
64
|
+
3. Create your account (first user is automatically admin)
|
|
65
|
+
4. Access the ROOT PROTOCOLS panel at the bottom
|
|
66
|
+
|
|
67
|
+
## 🔧 Configuration
|
|
68
|
+
|
|
69
|
+
YouClaw stores configuration in `.env` and uses SQLite for data persistence.
|
|
70
|
+
|
|
71
|
+
### Environment Variables
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
OLLAMA_HOST=http://localhost:11434
|
|
75
|
+
OLLAMA_MODEL=qwen2.5:1.5b-instruct
|
|
76
|
+
TELEGRAM_BOT_TOKEN=your_token_here
|
|
77
|
+
DISCORD_BOT_TOKEN=your_token_here
|
|
78
|
+
SEARCH_ENGINE_URL=http://your-search-engine/search
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## 🛡️ Security
|
|
82
|
+
|
|
83
|
+
- **Universal Admin**: Every user on your personal clone has full admin rights
|
|
84
|
+
- **Local-First**: All data stays on your machine
|
|
85
|
+
- **Token-Based Auth**: Secure session management for the dashboard
|
|
86
|
+
- **No Cloud Dependencies**: Runs entirely offline (except for bot platforms)
|
|
87
|
+
|
|
88
|
+
## 📝 License
|
|
89
|
+
|
|
90
|
+
MIT License - See LICENSE file for details
|
|
91
|
+
|
|
92
|
+
## 🤝 Contributing
|
|
93
|
+
|
|
94
|
+
Contributions are welcome! This is an open-source personal AI assistant project.
|
|
95
|
+
|
|
96
|
+
## 🐛 Issues
|
|
97
|
+
|
|
98
|
+
Report issues on GitHub: [Your Repository URL]
|
|
99
|
+
|
|
100
|
+
## 💬 Community
|
|
101
|
+
|
|
102
|
+
Join the discussion: [Your Community Link]
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
**Made with 🦞 by the YouClaw Community**
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0,<69.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "youclaw"
|
|
7
|
+
version = "4.6.0"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Imran", email="imran@example.com" },
|
|
10
|
+
]
|
|
11
|
+
description = "Your Personal AI Assistant - Universal Neural Core"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"License :: OSI Approved :: MIT License",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"aiosqlite",
|
|
21
|
+
"aiohttp",
|
|
22
|
+
"aiohttp-jinja2",
|
|
23
|
+
"jinja2",
|
|
24
|
+
"python-dotenv",
|
|
25
|
+
"apscheduler",
|
|
26
|
+
"python-telegram-bot",
|
|
27
|
+
"discord.py",
|
|
28
|
+
"httpx",
|
|
29
|
+
"beautifulsoup4",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.scripts]
|
|
33
|
+
youclaw = "youclaw.cli:main"
|
|
34
|
+
|
|
35
|
+
[tool.setuptools]
|
|
36
|
+
package-dir = {"" = "src"}
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.packages.find]
|
|
39
|
+
where = ["src"]
|
|
40
|
+
exclude = ["tests*", "data*", "*.log", ".env*"]
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.package-data]
|
|
43
|
+
youclaw = ["*.html", "*.css", "*.js"]
|
youclaw-4.6.0/setup.cfg
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""
|
|
2
|
+
YouClaw - Your Personal AI Assistant
|
|
3
|
+
Universal Neural Core for Telegram, Discord, and Web Dashboard
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
__version__ = "4.6.0"
|
|
7
|
+
__author__ = "Imran"
|
|
8
|
+
|
|
9
|
+
from .bot import youclaw_bot, main
|
|
10
|
+
from .config import config
|
|
11
|
+
from .memory_manager import memory_manager
|
|
12
|
+
from .ollama_client import ollama_client
|
|
13
|
+
from .scheduler_manager import scheduler_manager
|
|
14
|
+
from .skills_manager import skill_manager
|
|
15
|
+
|
|
16
|
+
__all__ = [
|
|
17
|
+
"youclaw_bot",
|
|
18
|
+
"main",
|
|
19
|
+
"config",
|
|
20
|
+
"memory_manager",
|
|
21
|
+
"ollama_client",
|
|
22
|
+
"scheduler_manager",
|
|
23
|
+
"skill_manager",
|
|
24
|
+
]
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"""
|
|
2
|
+
YouClaw - Your Personal AI Assistant
|
|
3
|
+
Main bot orchestrator that runs Discord and Telegram handlers concurrently.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import asyncio
|
|
7
|
+
import logging
|
|
8
|
+
import signal
|
|
9
|
+
import sys
|
|
10
|
+
from .config import config
|
|
11
|
+
from .ollama_client import ollama_client
|
|
12
|
+
from .memory_manager import memory_manager
|
|
13
|
+
from .scheduler_manager import scheduler_manager
|
|
14
|
+
from .discord_handler import discord_handler
|
|
15
|
+
from .telegram_handler import telegram_handler
|
|
16
|
+
from .dashboard import run_dashboard
|
|
17
|
+
from .skills_manager import skill_manager
|
|
18
|
+
|
|
19
|
+
# Set up logging
|
|
20
|
+
logging.basicConfig(
|
|
21
|
+
level=getattr(logging, config.bot.log_level),
|
|
22
|
+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
23
|
+
handlers=[
|
|
24
|
+
logging.StreamHandler(sys.stdout),
|
|
25
|
+
logging.FileHandler('youclaw.log')
|
|
26
|
+
]
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
logger = logging.getLogger(__name__)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class YouClaw:
|
|
33
|
+
"""Main YouClaw bot orchestrator"""
|
|
34
|
+
|
|
35
|
+
def __init__(self):
|
|
36
|
+
self.running = False
|
|
37
|
+
self.platform_tasks = []
|
|
38
|
+
self.dashboard_task = None
|
|
39
|
+
self.stop_event = asyncio.Event()
|
|
40
|
+
|
|
41
|
+
async def initialize(self):
|
|
42
|
+
"""Initialize bot cores"""
|
|
43
|
+
logger.info("🦞 Initializing YouClaw...")
|
|
44
|
+
|
|
45
|
+
# Initialize memory manager
|
|
46
|
+
await memory_manager.initialize()
|
|
47
|
+
|
|
48
|
+
# Initialize Ollama client
|
|
49
|
+
await ollama_client.initialize()
|
|
50
|
+
|
|
51
|
+
# Initialize scheduler manager
|
|
52
|
+
scheduler_manager.initialize(self, config.bot.database_path)
|
|
53
|
+
|
|
54
|
+
# Load dynamic skills
|
|
55
|
+
skill_manager.load_dynamic_skills()
|
|
56
|
+
|
|
57
|
+
logger.info("🤖 YouClaw Cores Initialized")
|
|
58
|
+
|
|
59
|
+
# Check Ollama health
|
|
60
|
+
if not await ollama_client.check_health():
|
|
61
|
+
logger.error("❌ Ollama is not available!")
|
|
62
|
+
# Don't exit here, maybe user will fix it via dashboard?
|
|
63
|
+
# Actually, we need Ollama for core features, but dashboard should stay up.
|
|
64
|
+
|
|
65
|
+
# Load initial config from DB
|
|
66
|
+
await config.refresh_from_db()
|
|
67
|
+
logger.info("🚀 YouClaw initialization complete!")
|
|
68
|
+
|
|
69
|
+
async def _start_platforms(self):
|
|
70
|
+
"""Internal method to start enabled platforms"""
|
|
71
|
+
# Clear existing tasks
|
|
72
|
+
for task in self.platform_tasks:
|
|
73
|
+
task.cancel()
|
|
74
|
+
self.platform_tasks = []
|
|
75
|
+
|
|
76
|
+
if config.discord.enabled and config.discord.token:
|
|
77
|
+
logger.info("Starting Discord handler...")
|
|
78
|
+
task = asyncio.create_task(discord_handler.start())
|
|
79
|
+
self.platform_tasks.append(task)
|
|
80
|
+
elif config.discord.enabled:
|
|
81
|
+
logger.warning("Discord enabled but no token provided!")
|
|
82
|
+
|
|
83
|
+
if config.telegram.enabled and config.telegram.token:
|
|
84
|
+
logger.info("Starting Telegram handler...")
|
|
85
|
+
task = asyncio.create_task(telegram_handler.start())
|
|
86
|
+
self.platform_tasks.append(task)
|
|
87
|
+
elif config.telegram.enabled:
|
|
88
|
+
logger.warning("Telegram enabled but no token provided!")
|
|
89
|
+
|
|
90
|
+
if not self.platform_tasks:
|
|
91
|
+
logger.info("No platform handlers started. Bot is in standby mode.")
|
|
92
|
+
|
|
93
|
+
async def start(self):
|
|
94
|
+
"""Start all enabled platform handlers"""
|
|
95
|
+
self.running = True
|
|
96
|
+
await self._start_platforms()
|
|
97
|
+
|
|
98
|
+
logger.info("✅ All platforms started. YouClaw is now online! 🦞")
|
|
99
|
+
|
|
100
|
+
# Keep running until stop_event is set
|
|
101
|
+
await self.stop_event.wait()
|
|
102
|
+
|
|
103
|
+
async def restart_handlers(self):
|
|
104
|
+
"""Refresh config and restart platform handlers ONLY (keep dashboard alive)"""
|
|
105
|
+
logger.info("♻️ Restarting handlers with fresh config...")
|
|
106
|
+
|
|
107
|
+
# Stop current platform handlers
|
|
108
|
+
await discord_handler.stop()
|
|
109
|
+
await telegram_handler.stop()
|
|
110
|
+
|
|
111
|
+
# Refresh configuration from database
|
|
112
|
+
await config.refresh_from_db()
|
|
113
|
+
|
|
114
|
+
# Start platforms again
|
|
115
|
+
await self._start_platforms()
|
|
116
|
+
logger.info("✅ Handlers restarted successfully")
|
|
117
|
+
|
|
118
|
+
async def shutdown(self):
|
|
119
|
+
"""Gracefully shutdown all components"""
|
|
120
|
+
logger.info("🛑 Shutting down YouClaw...")
|
|
121
|
+
self.running = False
|
|
122
|
+
|
|
123
|
+
# Set stop event to break the start() wait
|
|
124
|
+
self.stop_event.set()
|
|
125
|
+
|
|
126
|
+
# Cancel all platform tasks
|
|
127
|
+
for task in self.platform_tasks:
|
|
128
|
+
task.cancel()
|
|
129
|
+
|
|
130
|
+
# Cancel dashboard
|
|
131
|
+
if self.dashboard_task:
|
|
132
|
+
self.dashboard_task.cancel()
|
|
133
|
+
|
|
134
|
+
# Stop platform handlers
|
|
135
|
+
await discord_handler.stop()
|
|
136
|
+
await telegram_handler.stop()
|
|
137
|
+
|
|
138
|
+
# Close connections
|
|
139
|
+
await ollama_client.close()
|
|
140
|
+
await memory_manager.close()
|
|
141
|
+
|
|
142
|
+
logger.info("👋 YouClaw shutdown complete")
|
|
143
|
+
|
|
144
|
+
def handle_signal(self, sig):
|
|
145
|
+
"""Handle shutdown signals"""
|
|
146
|
+
logger.info(f"Received signal {sig}, initiating shutdown...")
|
|
147
|
+
asyncio.create_task(self.shutdown())
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
# Global bot instance
|
|
151
|
+
youclaw_bot = YouClaw()
|
|
152
|
+
|
|
153
|
+
async def main():
|
|
154
|
+
"""Main entry point"""
|
|
155
|
+
# Initialize cores
|
|
156
|
+
await youclaw_bot.initialize()
|
|
157
|
+
|
|
158
|
+
# Set up signal handlers
|
|
159
|
+
loop = asyncio.get_event_loop()
|
|
160
|
+
for sig in (signal.SIGTERM, signal.SIGINT):
|
|
161
|
+
loop.add_signal_handler(sig, lambda s=sig: youclaw_bot.handle_signal(s))
|
|
162
|
+
|
|
163
|
+
try:
|
|
164
|
+
# Start Dashboard as a background task
|
|
165
|
+
# We pass the bot instance so the dashboard can control it
|
|
166
|
+
logger.info("Starting Web Dashboard...")
|
|
167
|
+
youclaw_bot.dashboard_task = asyncio.create_task(run_dashboard(youclaw_bot, port=8080))
|
|
168
|
+
|
|
169
|
+
# Start bot handlers (this blocks until shutdown)
|
|
170
|
+
await youclaw_bot.start()
|
|
171
|
+
|
|
172
|
+
except asyncio.CancelledError:
|
|
173
|
+
pass
|
|
174
|
+
except Exception as e:
|
|
175
|
+
logger.error(f"Fatal error: {e}", exc_info=True)
|
|
176
|
+
finally:
|
|
177
|
+
await youclaw_bot.shutdown()
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
if __name__ == "__main__":
|
|
181
|
+
try:
|
|
182
|
+
asyncio.run(main())
|
|
183
|
+
except KeyboardInterrupt:
|
|
184
|
+
pass
|
|
185
|
+
|