forked from Rockachopa/Timmy-time-dashboard
This commit implements six major features: 1. Event Log System (src/swarm/event_log.py) - SQLite-based audit trail for all swarm events - Task lifecycle tracking (created, assigned, completed, failed) - Agent lifecycle tracking (joined, left, status changes) - Integrated with coordinator for automatic logging - Dashboard page at /swarm/events 2. Lightning Ledger (src/lightning/ledger.py) - Transaction tracking for Lightning Network payments - Balance calculations (incoming, outgoing, net, available) - Integrated with payment_handler for automatic logging - Dashboard page at /lightning/ledger 3. Semantic Memory / Vector Store (src/memory/vector_store.py) - Embedding-based similarity search for Echo agent - Fallback to keyword matching if sentence-transformers unavailable - Personal facts storage and retrieval - Dashboard page at /memory 4. Cascade Router Integration (src/timmy/cascade_adapter.py) - Automatic LLM failover between providers (Ollama → AirLLM → API) - Circuit breaker pattern for failing providers - Metrics tracking per provider (latency, error rates) - Dashboard status page at /router/status 5. Self-Upgrade Approval Queue (src/upgrades/) - State machine for self-modifications: proposed → approved/rejected → applied/failed - Human approval required before applying changes - Git integration for branch management - Dashboard queue at /self-modify/queue 6. Real-Time Activity Feed (src/events/broadcaster.py) - WebSocket-based live activity streaming - Bridges event_log to dashboard clients - Activity panel on /swarm/live Tests: - 101 unit tests passing - 4 new E2E test files for Selenium testing - Run with: SELENIUM_UI=1 pytest tests/functional/ -v --headed Documentation: - 6 ADRs (017-022) documenting architecture decisions - Implementation summary in docs/IMPLEMENTATION_SUMMARY.md - Architecture diagram in docs/architecture-v2.md
4.9 KiB
4.9 KiB
Implementation Summary: 3 New Features
Completed Features
1. Cascade Router Integration ✅
Files Created:
src/timmy/cascade_adapter.py- Adapter between Timmy and Cascade Routersrc/dashboard/routes/router.py- Dashboard routes for router statussrc/dashboard/templates/router_status.html- Router status UI
Files Modified:
src/dashboard/app.py- Registered router routessrc/dashboard/templates/base.html- Added ROUTER nav link
Usage:
from timmy.cascade_adapter import get_cascade_adapter
adapter = get_cascade_adapter()
response = await adapter.chat("Hello")
print(f"Response: {response.content}")
print(f"Provider: {response.provider_used}")
Dashboard: /router/status
2. Self-Upgrade Approval Queue ✅
Files Created:
src/upgrades/models.py- Database models for upgrades tablesrc/upgrades/queue.py- Queue management logicsrc/dashboard/routes/upgrades.py- Dashboard routessrc/dashboard/templates/upgrade_queue.html- Queue UI
Files Modified:
src/dashboard/app.py- Registered upgrade routessrc/dashboard/templates/base.html- Added UPGRADES nav link
Usage:
from upgrades.queue import UpgradeQueue
# Propose upgrade
upgrade = UpgradeQueue.propose(
branch_name="self-modify/fix-bug",
description="Fix bug in task assignment",
files_changed=["src/swarm/coordinator.py"],
diff_preview="@@ -123,7 +123,7 @@...",
)
# Approve
UpgradeQueue.approve(upgrade.id)
# Apply (runs tests, merges to main)
success, message = UpgradeQueue.apply(upgrade.id)
Dashboard: /self-modify/queue
3. Real-Time Activity Feed ✅
Files Created:
src/events/broadcaster.py- Bridge event_log → WebSocket
Files Modified:
src/swarm/event_log.py- Added broadcast callsrc/ws_manager/handler.py- Addedbroadcast_json()methodsrc/dashboard/templates/swarm_live.html- Added activity feed panel
Architecture:
Event Occurs → log_event() → SQLite
↓
event_broadcaster.broadcast_sync()
↓
ws_manager.broadcast_json()
↓
Dashboard (WebSocket)
Dashboard: /swarm/live (activity feed panel)
Test Results
Unit Tests: 101 passed
tests/test_event_log.py 25 passed
tests/test_ledger.py 18 passed
tests/test_vector_store.py 11 passed
tests/test_swarm.py 29 passed
tests/test_dashboard.py 18 passed
E2E Tests: Created (3 new test files)
tests/functional/test_cascade_router_e2e.pytests/functional/test_upgrade_queue_e2e.pytests/functional/test_activity_feed_e2e.py
Running E2E Tests (Non-Headless)
Watch the browser execute tests in real-time:
# 1. Start the server
cd /Users/apayne/Timmy-time-dashboard
source .venv/bin/activate
make dev
# 2. In another terminal, run E2E tests
source .venv/bin/activate
SELENIUM_UI=1 pytest tests/functional/test_cascade_router_e2e.py -v --headed
# Or run all E2E tests
SELENIUM_UI=1 pytest tests/functional/ -v --headed
The --headed flag runs Chrome in visible mode so you can watch.
Database Schema Updates
Three new tables created automatically:
-- Event Log (existing, now with broadcast)
CREATE TABLE event_log (...);
-- Lightning Ledger (existing)
CREATE TABLE ledger (...);
-- Vector Store (existing)
CREATE TABLE memory_entries (...);
-- NEW: Upgrade Queue
CREATE TABLE upgrades (
id TEXT PRIMARY KEY,
status TEXT NOT NULL,
proposed_at TEXT NOT NULL,
branch_name TEXT NOT NULL,
description TEXT NOT NULL,
files_changed TEXT,
diff_preview TEXT,
test_passed INTEGER DEFAULT 0,
test_output TEXT,
error_message TEXT,
approved_by TEXT
);
Navigation Updates
New nav links in dashboard header:
- EVENTS →
/swarm/events - LEDGER →
/lightning/ledger - MEMORY →
/memory - ROUTER →
/router/status - UPGRADES →
/self-modify/queue
Architecture Alignment
All 3 features follow existing patterns:
- Singleton pattern for services (cascade_adapter, event_broadcaster)
- SQLite persistence through consistent DB access pattern
- Dashboard routes following existing route structure
- Jinja2 templates extending base.html
- Event-driven using existing event log infrastructure
- WebSocket using existing ws_manager
Security Considerations
| Feature | Risk | Mitigation |
|---|---|---|
| Cascade Router | API key exposure | Uses existing config system |
| Upgrade Queue | Unauthorized changes | Human approval required |
| Activity Feed | Data leak | Events sanitized before broadcast |
Next Steps
- Run E2E tests with
SELENIUM_UI=1 pytest tests/functional/ -v --headed - Manually test each dashboard page
- Verify WebSocket real-time updates in
/swarm/live - Test upgrade queue workflow end-to-end