mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-10-02 13:39:41 +02:00
Create 6 domain-focused config files in src/config/ to centralize operational tuning knobs that were scattered across 15+ source files: - server-timing.ts: SSE batching, state debounce, scheduled runs, error recovery - auth-config.ts: session TTL, rate limits, hook timeout - tunnel-config.ts: QR token rotation, tunnel process lifecycle - terminal-limits.ts: input length, terminal cols/rows, session name - ai-defaults.ts: AI model string, idle/plan context limits - team-config.ts: poll interval, cache sizes Eliminates all cross-file duplicates: - AI model string: 5 occurrences → 1 (config only) - STATS_COLLECTION_INTERVAL_MS: 2 → 1 - timeout: 10000 in hooks-config: 6 → 0 (now HOOK_TIMEOUT_MS) - MAX_TRACKED_AGENTS shadow: removed, imports from map-limits Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* @fileoverview Codeman CLI entry point
|
|
*
|
|
* This is the main executable entry point for the Codeman CLI.
|
|
* It sets up global error handlers and invokes the CLI parser.
|
|
*
|
|
* @module index
|
|
*/
|
|
|
|
import { program } from './cli.js';
|
|
|
|
// Detect if we're running the web server (long-lived process)
|
|
// In web mode, we should NOT exit on transient errors — log and continue
|
|
const isWebMode = process.argv.includes('web');
|
|
|
|
import { MAX_CONSECUTIVE_ERRORS, ERROR_RESET_MS } from './config/server-timing.js';
|
|
|
|
// Track consecutive unhandled errors in web mode — restart after too many
|
|
let consecutiveErrors = 0;
|
|
let errorResetTimer: ReturnType<typeof setTimeout> | null = null;
|
|
|
|
function trackError(): void {
|
|
consecutiveErrors++;
|
|
if (errorResetTimer) clearTimeout(errorResetTimer);
|
|
errorResetTimer = setTimeout(() => {
|
|
consecutiveErrors = 0;
|
|
}, ERROR_RESET_MS);
|
|
|
|
if (consecutiveErrors >= MAX_CONSECUTIVE_ERRORS) {
|
|
console.error(`[FATAL] ${MAX_CONSECUTIVE_ERRORS} consecutive unhandled errors — exiting for systemd restart`);
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
// Handle uncaught errors
|
|
process.on('uncaughtException', (err) => {
|
|
console.error('Uncaught exception:', err.message);
|
|
if (isWebMode) {
|
|
console.error('[RECOVERED] Server continuing after uncaught exception:', err.stack);
|
|
trackError();
|
|
} else {
|
|
process.exit(1);
|
|
}
|
|
});
|
|
|
|
process.on('unhandledRejection', (reason) => {
|
|
console.error('Unhandled rejection:', reason);
|
|
if (isWebMode) {
|
|
console.error('[RECOVERED] Server continuing after unhandled rejection');
|
|
trackError();
|
|
} else {
|
|
process.exit(1);
|
|
}
|
|
});
|
|
|
|
// Run CLI
|
|
program.parse();
|