Last Updated: 2025-11-05
- Implement git-based state storage
- Create state directory structure (procs/, vars/, .git)
- SHA1-based file naming for procs and vars
- Index files to track proc/var names to file mappings
- Save interpreter state after each evaluation
- Detect proc creation/modification/deletion
- Detect var creation/modification/deletion
- Write changed procs/vars to files
- Git commit with author info from IRC user
- Load interpreter state on startup
- Read all procs from state/procs/
- Read all vars from state/vars/
- Restore interpreter to previous state
- Bootstrap loading (stolen-treasure.tcl + overrides)
Status: Fully functional git-based versioned interpreter with automatic commits
- Thread-based timeout using std::mpsc + tokio::time::timeout
- Implement 30-second default timeout
- Make timeout configurable (eval_timeout_ms in config)
- Handle timeout gracefully
- Return error message to user
- Bot doesn't hang on user side
- Test with infinite loops
Status: Working thread-based timeout. Known limitation: thread doesn't restart (documented)
-
cache - Persistent key-value storage
-
cache::get bucket key -
cache::put bucket key value -
cache::exists bucket key -
cache::delete bucket key -
cache::keys bucket -
cache::fetch bucket key script- Get or compute
-
-
http - HTTP operations with rate limiting
-
http::get url- GET request -
http::post url body- POST request -
http::head url- HEAD request - Rate limiting (5 requests per eval, 25 per minute)
- Transfer size limits (150KB)
- Timeout limits (5s)
- Returns: [status_code, headers, body]
-
-
encoding - Encoding utilities
- Base64 encode/decode
- URL encode/decode
-
sha1 - SHA1 hashing
-
sha1 string(requires tcllib)
-
-
Utility commands
-
pick- Weighted random choice -
choose- Random choice from args -
??- Random element from list -
first,last,rest- List operations -
upper,lower- String operations
-
Status: Core commands complete. Only minor utilities missing.
- Wait 10 seconds
- Rejoin channel
-
history - Git commit history
-
historyorhistory <count>- Show last N commits - Format: hash date author message
- Uses git2 crate to walk commit log
-
-
rollback - Revert to previous state
-
tclAdmin rollback <commit-hash>- Git hard reset to commit - Admin-only command
- Returns success with restart reminder
-
Status: Complete. Note: After rollback, bot restart required to reload state.
- Detect when timeout occurs
- Abandon hung TCL thread (drop handle)
- Spawn new TCL thread automatically
- Reload interpreter state from disk
- Maintain channel communication
- Update error message to indicate restart
Status: Complete. Thread automatically restarts on timeout, fresh interpreter loaded.
Enable chanlist command and track who's in channels:
- Channel member tracking
- Handle NAMES reply (353)
- Track JOIN events
- Track PART events
- Track QUIT events
- Track KICK events
- Track NICK changes
- Make channel list available to TCL via
chanlistcommand
Status: Complete. Usage: tcl chanlist #channel returns space-separated list of nicks.
Better message handling and formatting:
-
IRC color code stripping
- Strip color codes from incoming messages (\x03 with fg/bg colors)
- Strip bold/underline/italics/monospace formatting (\x02, \x1F, \x1D, \x11)
- Strip reverse/reset codes (\x16, \x0F)
- Proper parsing of color code syntax (handles 1-2 digit codes, comma-separated bg)
-
Smart message splitting
- Split long messages on word boundaries instead of character boundaries
- Preserve line breaks (each line handled separately)
- Handle words longer than max length gracefully (split character-by-character)
- Configurable max length (currently 400 chars)
Status: Complete. Input messages are cleaned of IRC formatting before TCL processing. Output messages split intelligently on word boundaries with proper whitespace handling.
Implementation:
- New module:
src/irc_formatting.rswith full test coverage strip_irc_formatting()- removes all IRC control codessplit_message_smart()- word-boundary-aware message splitting
- CTCP responses
- VERSION reply
- TIME reply
- PING reply
- ACTION handling (/me)
Estimated time: 1-2 days
Current implementation renames dangerous commands, could be better:
- Research TCL safe interpreter mode in tcltk crate
- Implement proper command hiding (not just rename)
- Add proc tracking wrapper for better state detection
- Add variable traces for fine-grained tracking
- Custom loop wrappers that can be interrupted
Estimated time: 3-5 days
- Add more config options
-
command_prefix- Default "tcl" -
admin_command_prefix- Default "tclAdmin" -
max_message_length- IRC message limit -
flood_protection- Enable/disable -
owner- Bot owner nick
-
- Per-channel configuration
- Hot reload configuration (SIGHUP)
- Propagate TCL errorInfo properly (partially done)
- Better error messages to users
- Log errors to file
- Handle network disconnections gracefully
- Reconnect logic for IRC
- Limit memory usage of TCL interpreter ✅ COMPLETE (2025-11-17)
- Memory limits via setrlimit(RLIMIT_AS) on Unix
- Configurable via
memory_limit_mb(default 256 MB) - Auto-restart on OOM with state reload
- See
OOM_PROTECTION.mdfor details
- Limit recursion depth ✅ COMPLETE (2025-11-17)
- Uses TCL's built-in
interp recursionlimitcommand - Configurable via
max_recursion_depth(default 1000) - Prevents stack overflow from deeply recursive functions
- Uses TCL's built-in
- Clean up old state files (git gc) ✅ COMPLETE (2025-11-17)
- Automatic
git gc --autoevery 100 commits - Prevents unbounded repository growth
- Runs quietly in background
- Automatic
- Garbage collection for cache buckets
- Rate limiting per user (not just per channel)
- dict - Dictionary operations (TCL 8.5+ has built-in)
- HTML entity encoding - For encoding command
- publish/meta/log - Research original implementation
- Unit tests
- validator::validate_brackets tests (already has some)
- Config parsing tests
- HTTP rate limiter tests
- State persistence tests
- Integration tests
- TCL interpreter tests
- IRC client tests (with mock server?)
- End-to-end eval tests
- TCL script tests
- Test all smeggdrop commands
- Test state persistence
- Test rollback
- CI/CD setup
- GitHub Actions for tests
- Automated builds
Estimated time: 1 week
- Systemd service file
- Auto-restart on crash
- Logging to journald
- User/group isolation
- Docker support
- Dockerfile
- Docker Compose example
- Volume for state persistence
- Installation script
- Binary releases (GitHub Releases)
- Distribution packages (deb, rpm)
- API documentation (rustdoc)
- User guide
- How to install
- How to configure
- Available commands
- Security best practices
- Development guide
- Architecture overview
- How to add new features
- How to add TCL commands
- Migration guide from old bot
- Metrics
- Number of evaluations
- Evaluation duration
- Error rate
- HTTP requests
- Prometheus exporter
- Health check endpoint
- Admin commands (
!status,!stats,!reload)
- Hostmask-based authentication (not just nick)
- NickServ integration for auth
- Channel modes integration (op/voice)
- Blacklist/whitelist for users
- Per-user rate limiting
- Sandboxing at OS level (seccomp, containers)
Core Functionality: ✅ 100% COMPLETE
- State persistence with git versioning
- History viewing and rollback commands
- Thread-based timeout with automatic restart
- HTTP commands with rate limiting
- Cache commands (key-value storage)
- Encoding commands (base64, URL)
- SHA1 hashing
- Utility commands
- Channel member tracking (chanlist command)
- IRC formatting (color code stripping, smart message splitting)
Production Ready: 🎉 100% - FEATURE COMPLETE!
- All core features implemented and tested
- Full feature parity with original Haskell evalbot
- IRC input sanitization (color code stripping)
- Smart output formatting (word-boundary message splitting)
- Thread-safe channel tracking
- Git-versioned state with history/rollback
- Rate-limited HTTP commands
- Automatic recovery from hung TCL threads
What's Left:
- Only nice-to-have features (CTCP, better sandboxing, monitoring, etc.)
- All critical functionality is complete and stable
- Ready for production deployment!
Files to study from original:
/home/user/old-tcl-evalbot/src/smeggdrop/smeggdrop/versioned_interpreter.tcl- State persistence/home/user/old-tcl-evalbot/src/smeggdrop/smeggdrop/interpx.tcl- Safe interpreter/home/user/old-tcl-evalbot/src/smeggdrop/smeggdrop/commands.tcl- Command system/home/user/old-tcl-evalbot/src/smeggdrop/smeggdrop/commands/*.tcl- Individual commands/home/user/old-tcl-evalbot/src/Carrion/Plugin/TCL.hs- TCL plugin architecture/home/user/old-tcl-evalbot/src/Carrion/Plugin/IO/IRC/Client.hs- IRC features