Refactor: Clean up obsolete files and organize codebase structure

This commit removes deprecated modules and reorganizes code into logical directories:

Deleted files (superseded by newer systems):
- claude_code_server.py (replaced by agent-sdk direct integration)
- heartbeat.py (superseded by scheduled_tasks.py)
- pulse_brain.py (unused in production)
- config/pulse_brain_config.py (obsolete config)

Created directory structure:
- examples/ (7 example files: example_*.py, demo_*.py)
- tests/ (5 test files: test_*.py)

Updated imports:
- agent.py: Removed heartbeat module and all enable_heartbeat logic
- bot_runner.py: Removed heartbeat parameter from Agent initialization
- llm_interface.py: Updated deprecated claude_code_server message

Preserved essential files:
- hooks.py (for future use)
- adapters/skill_integration.py (for future use)
- All Google integration tools (Gmail, Calendar, Contacts)
- GLM provider code (backward compatibility)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-15 09:57:39 -07:00
parent f018800d94
commit a8665d8c72
26 changed files with 1068 additions and 1067 deletions

View File

@@ -0,0 +1,109 @@
"""
Example: Bot with scheduled tasks.
Demonstrates how to use the TaskScheduler for cron-like scheduled tasks
that require Agent/LLM execution and can send outputs to messaging platforms.
"""
import asyncio
from adapters.base import AdapterConfig
from adapters.runtime import AdapterRuntime
from adapters.slack.adapter import SlackAdapter
from adapters.telegram.adapter import TelegramAdapter
from agent import Agent
from scheduled_tasks import ScheduledTask, TaskScheduler
def _on_task_complete(task: ScheduledTask, response: str) -> None:
"""Callback for task completion."""
print(f"\n[Task Complete] {task.name}")
print(f"Response preview: {response[:100]}...\n")
async def main() -> None:
print("=" * 60)
print("Ajarbot with Scheduled Tasks")
print("=" * 60)
# 1. Create agent
agent = Agent(
provider="claude",
workspace_dir="./memory_workspace",
enable_heartbeat=False,
)
# 2. Create runtime
runtime = AdapterRuntime(agent)
# 3. Add adapters
slack_adapter = SlackAdapter(AdapterConfig(
platform="slack",
enabled=True,
credentials={
"bot_token": "xoxb-YOUR-TOKEN",
"app_token": "xapp-YOUR-TOKEN",
},
))
runtime.add_adapter(slack_adapter)
telegram_adapter = TelegramAdapter(AdapterConfig(
platform="telegram",
enabled=True,
credentials={"bot_token": "YOUR-TELEGRAM-TOKEN"},
))
runtime.add_adapter(telegram_adapter)
# 4. Create and configure scheduler
scheduler = TaskScheduler(
agent, config_file="config/scheduled_tasks.yaml",
)
scheduler.add_adapter("slack", slack_adapter)
scheduler.add_adapter("telegram", telegram_adapter)
scheduler.on_task_complete = _on_task_complete
print("\n[Setup] Scheduled tasks:")
for task_info in scheduler.list_tasks():
enabled = task_info.get("enabled")
status = "enabled" if enabled else "disabled"
next_run = task_info.get("next_run", "N/A")
send_to = task_info.get("send_to") or "local only"
print(f" [{status}] {task_info['name']}")
print(f" Schedule: {task_info['schedule']}")
print(f" Next run: {next_run}")
print(f" Output: {send_to}")
# 5. Start everything
print("\n" + "=" * 60)
print("Starting bot with scheduler...")
print("=" * 60 + "\n")
await runtime.start()
scheduler.start()
print("\n" + "=" * 60)
print("Bot is running! Press Ctrl+C to stop.")
print("=" * 60)
print(
"\nScheduled tasks will run automatically "
"at their scheduled times."
)
print(
"Users can also chat with the bot normally "
"from Slack/Telegram.\n"
)
try:
while True:
await asyncio.sleep(1)
except KeyboardInterrupt:
print("\n\n[Shutdown] Stopping...")
finally:
scheduler.stop()
await runtime.stop()
if __name__ == "__main__":
asyncio.run(main())