Overview
Located atsrc/athena/tools/heartbeat.py, this module provides:
- Read-only operation - Only reads source files, never modifies them
- Debounced syncing - 5-second debounce window for rapid edits
- Automatic table routing - Maps directories to Supabase tables
- Single-scan mode - For CI/CD and initial indexing
Class Signature
Parameters
dry_run- Log what would be synced without actually syncing (default: False)
Architecture
Directory Watching
Heartbeat watches directories defined inathena.core.config:
Table Routing
Files are automatically routed to Supabase tables based on their directory:Debouncing
Rapid file edits are batched using a 5-second debounce window:- User saves
protocol.mdat t=0s β timer starts - User saves again at t=2s β timer resets to t=7s
- User saves again at t=4s β timer resets to t=9s
- No more edits β sync executes at t=9s (one sync for 3 saves)
Event Handling
Two file system events trigger syncs:File Filters
Sync Operation
The actual sync delegates toathena.memory.sync:
Logging
All events are logged to.athena/heartbeat.log and stderr:
CLI Usage
Daemon Mode (Default)
Run as a foreground daemon:Dry Run Mode
Test without syncing:Single Scan Mode
Scan all directories once and exit (useful for CI/CD):Single-Scan Implementation
The--once mode uses manifest-based change detection:
Dependencies
Heartbeat requires thewatchdog library:
Statistics Tracking
Use Cases
Development Workflow
Run in a tmux/screen session during active development:CI/CD Pipeline
Run single scan after content changes:Testing Changes
Use dry-run to verify routing:Integration Example
Safety Features
Read-Only Guarantee
Heartbeat never writes to source files:Error Handling
Sync failures are logged but donβt crash the daemon:Related
Memory Sync
Supabase sync implementation
Configuration
Directory and table mappings