Fix working directory issue - enable claude-remote to run from any directory (#7)

* Fix self-reply loop issue when using same email for send/receive

- Add Message-ID tracking to prevent processing system-sent emails
- Track sent emails in sent-messages.json with auto-cleanup
- Skip system emails in both email-listener.js and relay-pty.js
- Extract session from token/headers/body for proper reply routing
- Reduce verbose logging in tmux-injector to debug level

Fixes #3

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix working directory issue - enable claude-remote to run from any directory

- Use absolute path to load .env file instead of relying on current working directory
- Fix environment variable loading in both main program and relay service
- Now claude-remote can be executed from any directory

Fixes #5

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Song-Ze Yu 2025-08-01 12:28:39 +08:00 committed by GitHub
parent db20186423
commit b957cbbcc8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 70 deletions

View File

@ -5,8 +5,10 @@
* Main entry point for the CLI tool
*/
// Load environment variables
require('dotenv').config();
// Load environment variables from Claude-Code-Remote directory
const path = require('path');
const envPath = path.join(__dirname, '.env');
require('dotenv').config({ path: envPath });
const Logger = require('./src/core/logger');
const Notifier = require('./src/core/notifier');

View File

@ -5,12 +5,13 @@
* Uses node-imap instead of ImapFlow to resolve Feishu email compatibility issues
*/
require('dotenv').config();
const path = require('path');
const envPath = path.join(__dirname, '../../.env');
require('dotenv').config({ path: envPath });
const Imap = require('node-imap');
const { simpleParser } = require('mailparser');
const { spawn } = require('node-pty');
const { existsSync, readFileSync, writeFileSync } = require('fs');
const path = require('path');
const pino = require('pino');
// Configure logging

View File

@ -1,66 +0,0 @@
#!/usr/bin/env node
/**
* Test SMTP connection using environment variables
*/
require('dotenv').config();
const nodemailer = require('nodemailer');
async function testSMTP() {
console.log('🔧 Testing SMTP connection...\n');
const config = {
host: process.env.SMTP_HOST || 'smtp.gmail.com',
port: parseInt(process.env.SMTP_PORT) || 587,
secure: process.env.SMTP_SECURE === 'true',
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
}
};
console.log('📋 SMTP Configuration:');
console.log(` Host: ${config.host}`);
console.log(` Port: ${config.port}`);
console.log(` Secure: ${config.secure}`);
console.log(` User: ${config.auth.user}`);
console.log(` Pass: ${'*'.repeat(config.auth.pass?.length || 0)}\n`);
try {
const transporter = nodemailer.createTransport(config);
console.log('🔄 Verifying connection...');
await transporter.verify();
console.log('✅ SMTP connection successful!\n');
console.log('📧 Sending test email...');
const info = await transporter.sendMail({
from: process.env.EMAIL_FROM || `Claude Code Remote <${process.env.SMTP_USER}>`,
to: process.env.EMAIL_TO,
subject: 'Claude Code Remote - SMTP Test',
text: 'This is a test email from Claude Code Remote. If you receive this, SMTP is working correctly!'
});
console.log(`✅ Test email sent successfully!`);
console.log(`📧 Message ID: ${info.messageId}`);
console.log(`📬 To: ${process.env.EMAIL_TO}`);
} catch (error) {
console.error('❌ SMTP test failed:', error.message);
if (error.code === 'EAUTH') {
console.error('\n💡 Authentication failed. Please check:');
console.error(' - Gmail App Password is correct');
console.error(' - Two-factor authentication is enabled');
console.error(' - Email credentials in .env file');
} else if (error.code === 'ETIMEDOUT') {
console.error('\n💡 Connection timeout. Please check:');
console.error(' - Internet connection');
console.error(' - Firewall settings');
console.error(' - SMTP host and port');
}
}
}
testSMTP().catch(console.error);