Skip to content

Conversation

@kevinsslin
Copy link
Contributor

@kevinsslin kevinsslin commented Jul 28, 2025

Summary

This PR removes all hardcoded values throughout the codebase and implements a comprehensive environment-variable-based configuration system, making the application fully configurable for production deployment and open-source distribution.

Key Changes

Configuration System Overhaul

  • Environment-first approach: All SMTP/IMAP settings, paths, and timeouts now load from environment variables
  • Zero hardcoded credentials: Removed all hardcoded email addresses, hosts, ports, and user-specific paths
  • Cross-platform compatibility: Replaced hardcoded user paths (/Users/jessytsui/.nvm/...) with configurable CLAUDE_CLI_PATH
  • Backward compatible: Maintains existing functionality while adding comprehensive configuration options

Email System Improvements

  • Fixed email reply token extraction: Added support for "Re: " prefix in email replies - when users reply to Claude-Code-Remote emails, the system now correctly extracts tokens from subjects like Re: [Claude-Code-Remote #TOKEN] ...
  • Updated token format: Fixed email reply processing to match new [Claude-Code-Remote #TOKEN] format (resolves "No token found in email" errors)
  • Configurable SMTP timeouts: Added SMTP_TIMEOUT environment variable for connection reliability
  • Dynamic test tokens: Test scripts now generate tokens dynamically instead of using hardcoded values

Security & Reliability

  • Production ready: All sensitive values externalized to environment variables
  • Configurable timeouts: SMTP connections, desktop notifications, and command execution all configurable
  • Improved error handling: Better connection reliability and debugging

Environment Variables Added

Core Email Configuration

SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_SECURE=true
[email protected]
SMTP_PASS=your-app-password

IMAP_HOST=imap.gmail.com
IMAP_PORT=993
IMAP_SECURE=true
[email protected]
IMAP_PASS=your-app-password

[email protected]
[email protected]

System & Timeout Configuration

CLAUDE_CLI_PATH=claude
SESSION_MAP_PATH=/path/to/session-map.json
SMTP_TIMEOUT=10000
NOTIFICATION_TIMEOUT=3000
COMMAND_TIMEOUT=10000
LOG_LEVEL=info

Files Modified

Core Configuration

  • src/core/config.js - Environment-first configuration loading
  • claude-remote.js - Added dotenv integration
  • .env.example - Complete configuration documentation

Email & Communication

  • src/channels/email/smtp.js - Configurable SMTP timeouts
  • src/relay/relay-pty.js - Fixed token extraction for Claude-Code-Remote format + email reply support
  • src/channels/local/desktop.js - Configurable notification timeouts
  • config/channels.json - Removed hardcoded email settings

System Integration

  • claude-control.js - Configurable Claude CLI path
  • send-test-reply.js - Dynamic token generation
  • test-smtp.js - New comprehensive testing utility

Recent Updates

Email Reply Fix (Latest Commit)

  • Fixed "Re: " prefix handling: Email clients automatically add "Re: " when replying, which was preventing token extraction
  • Added regex pattern: Now supports both [Claude-Code-Remote #TOKEN] and Re: [Claude-Code-Remote #TOKEN] formats
  • Immediate fix: Resolves the "No token found in email" issue when users reply to Claude-Code-Remote emails

Testing Results

  • ✅ Email delivery and SMTP connections working with environment configuration
  • ✅ Email reply processing fixed - tokens now properly extracted from both original and reply formats
  • ✅ Dynamic token generation and authentication flow verified
  • ✅ Cross-platform compatibility confirmed
  • ✅ All timeout configurations functional

Migration Guide

Existing users: Copy .env.example to .env and configure your settings. All functionality preserved.

New users: Follow the setup guide in .env.example for complete configuration.

Important: After updating, restart the relay process to load the new email reply fix: node src/relay/relay-pty.js

Type of Change

  • Bug fix (fixes email reply token extraction + removes deployment-blocking hardcoded values)
  • Enhancement (comprehensive configuration system)
  • Security improvement (externalizes sensitive data)
  • Breaking change (maintains backward compatibility)

- Replace hardcoded email addresses with SMTP_USER environment variable
- Add session files to gitignore to prevent runtime data commits
- Make email filtering use existing SMTP_USER instead of adding new EMAIL_FROM

This simple fix makes the tool more portable without adding unnecessary
complexity or new configuration variables.
## 🔧 Core Configuration Improvements
- **Environment Variable Integration**: Updated ConfigManager to automatically load all SMTP/IMAP settings from environment variables
- **Dynamic Configuration**: Replaced hardcoded email configurations with dynamic environment-based loading
- **Simplified Configuration**: Removed redundant hardcoded values from config/channels.json

## 🛠️ Hardcoded Values Removal
- **User Path Fix**: Replaced hardcoded user-specific Claude CLI path with configurable CLAUDE_CLI_PATH environment variable
- **Dynamic Test Tokens**: Made test tokens dynamic instead of hardcoded values
- **Configurable Timeouts**: All timeout values now use environment variables (SMTP_TIMEOUT, NOTIFICATION_TIMEOUT, etc.)
- **SMTP Settings**: All SMTP connection timeouts now configurable via environment variables

## 📧 Email System Enhancements
- **Automatic Provider Detection**: Email configuration automatically enables when SMTP_USER is provided
- **Better Error Handling**: Improved SMTP connection reliability with configurable timeouts
- **Test Suite**: Added comprehensive SMTP testing script with dynamic configuration

## 🔒 Security & Portability
- **No Hardcoded Credentials**: All email addresses, hosts, and ports now come from environment variables
- **Cross-Platform**: Removed user-specific paths and made system calls configurable
- **Environment-First**: All configuration now follows environment variable best practices

## 📝 Files Modified
- src/core/config.js: Enhanced to load all settings from environment variables
- claude-control.js: Removed hardcoded user path, now uses CLAUDE_CLI_PATH
- src/channels/email/smtp.js: Configurable SMTP timeouts
- src/channels/local/desktop.js: Configurable notification timeouts
- send-test-reply.js: Dynamic token generation and proper authentication
- config/channels.json: Removed hardcoded email settings
- test-smtp.js: Added comprehensive SMTP testing utility

## ✅ Testing
- All notification systems tested and working
- SMTP connection verified with new timeout settings
- Dynamic token generation confirmed
- Environment variable loading verified
- Cross-platform compatibility maintained
- Document all new environment variables for timeouts and configuration
- Include examples for multiple email providers (Gmail, QQ, 163, Outlook)
- Provide clear setup instructions and best practices
- Cover all timeout settings, paths, and optional configurations
@kevinsslin kevinsslin changed the title Fix hardcoded email address and improve gitignore 🚀 Comprehensive Hardcoded Values Cleanup & Environment-First Configuration System Jul 28, 2025
@kevinsslin kevinsslin changed the title 🚀 Comprehensive Hardcoded Values Cleanup & Environment-First Configuration System Remove hardcoded values and implement environment-based configuration Jul 28, 2025
- Update token extraction pattern to match [Claude-Code-Remote #TOKEN] format
- Remove legacy TaskPing patterns to avoid confusion
- This fixes the "No token found in email" error when replying to notifications
Add regex pattern to handle email replies with "Re: " prefix.
When users reply to Claude-Code-Remote emails, email clients
add "Re: " which was preventing token extraction.
@JessyTsui
Copy link
Owner

LGTM! This PR nicely addresses the hardcoded values I left in the code when I rushed the initial upload.

@JessyTsui JessyTsui merged commit e5de5a7 into JessyTsui:master Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants