-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
64 lines (53 loc) · 2.33 KB
/
Copy pathindex.ts
File metadata and controls
64 lines (53 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// index.ts — ZeroClaw Claude daemon entry point
import fs from 'fs';
import { loadConfig, PID_FILE, ensureConfigDir } from './config.js';
import { startScheduler, stopScheduler } from './scheduler/index.js';
import { startHeartbeat, stopHeartbeat } from './daemon/heartbeat.js';
import { startTelegramBot, stopTelegramBot } from './bot/telegram.js';
import { startDashboard, stopDashboard } from './dashboard/server.js';
import { log } from './daemon/logger.js';
const BANNER = `
╔══════════════════════════════════════════════════╗
║ ⚡ Z E R O C L A W — C L A U D E ║
║ Daemon for Claude Code · v1.0.0 ║
╚══════════════════════════════════════════════════╝
`;
async function main(): Promise<void> {
console.log(BANNER);
ensureConfigDir();
// Write PID file
fs.writeFileSync(PID_FILE, String(process.pid), 'utf-8');
const config = loadConfig();
log.info(`Starting ZeroClaw Claude daemon`);
log.info(`Model: ${config.model} | Security: ${config.security}`);
// Start subsystems
startScheduler();
startHeartbeat();
await startTelegramBot();
startDashboard();
log.info(`Dashboard: http://127.0.0.1:${config.dashboardPort}`);
log.info(`Daemon ready — PID ${process.pid}`);
// ── Graceful shutdown ──────────────────────────────────────────────────────
const shutdown = async (signal: string) => {
log.info(`Received ${signal} — shutting down...`);
stopHeartbeat();
stopScheduler();
await stopTelegramBot();
stopDashboard();
try { fs.unlinkSync(PID_FILE); } catch {}
log.info('ZeroClaw Claude stopped.');
process.exit(0);
};
process.on('SIGINT', () => shutdown('SIGINT'));
process.on('SIGTERM', () => shutdown('SIGTERM'));
process.on('uncaughtException', (err) => {
log.error(`Uncaught exception: ${err.message}`);
});
process.on('unhandledRejection', (reason) => {
log.error(`Unhandled rejection: ${reason}`);
});
}
main().catch((err) => {
console.error('Fatal startup error:', err);
process.exit(1);
});