railyard/apps/rithub-mcp/ecosystem.config.cjs
caelum0x 0cad0168ab chore(rithub-mcp): load ANTHROPIC_API_KEY for the agent worker from /etc/products/rithub-mcp.env
Dependency-free KEY=VALUE loader in ecosystem.config.cjs, same
/etc/products/*.env convention relay/openjev already use on railyard-box,
so the agent PR loop's Claude call has a real key in production without
adding a dotenv dependency. No-op (empty object) when the file isn't
present, e.g. local dev.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-11-19 02:15:20 +03:00

66 lines
2.2 KiB
JavaScript

// pm2 process definitions for the Rithub MCP server and its agent-PR-loop
// worker. Both bound to 127.0.0.1 only -- public exposure for the HTTP
// server is via the existing Caddy reverse proxy for rithub.dev (see
// /etc/caddy/sites-enabled/rithub-dev.caddy); the worker has no HTTP
// surface at all, it only polls the engine's own loopback API.
const fs = require("node:fs");
// Minimal, dependency-free KEY=VALUE loader (no quoting/escaping support
// needed for the one secret this reads) -- same `/etc/products/*.env`
// convention already used by relay/openjev/etc. on this box, read at pm2
// start/reload time rather than adding a dotenv dependency.
function loadEnvFile(path) {
try {
const out = {};
for (const line of fs.readFileSync(path, "utf8").split("\n")) {
const match = /^([A-Z0-9_]+)=(.*)$/.exec(line.trim());
if (match) out[match[1]] = match[2];
}
return out;
} catch {
return {}; // file not present (e.g. local dev) -- CLAUDE_API_KEY/ANTHROPIC_API_KEY stay unset, the agent worker just logs and skips proposeFix.
}
}
const secrets = loadEnvFile("/etc/products/rithub-mcp.env");
module.exports = {
apps: [
{
name: "rithub-mcp",
cwd: __dirname,
script: "bin/start.mjs",
env: {
NODE_ENV: "production",
PORT: "3351",
HOST: "127.0.0.1",
// Talk to the engine directly on-box, not through the public
// rithub.dev domain: Cloudflare's edge proxy in front of
// rithub.dev hard-times-out around ~100s, which a slow
// repos/migrate call (import_from_github) can exceed even for a
// small repo (confirmed live, 2026-11-18: a 524 from Cloudflare
// on a plain octocat/Hello-World migrate). The engine's own port
// has no such limit.
RITHUB_BASE_URL: "http://127.0.0.1:3350",
},
autorestart: true,
max_restarts: 10,
min_uptime: "10s",
},
{
name: "rithub-agent-worker",
cwd: __dirname,
script: "bin/agent-worker.mjs",
env: {
NODE_ENV: "production",
RITHUB_BASE_URL: "http://127.0.0.1:3350",
AGENT_POLL_INTERVAL_MS: "20000",
...secrets,
},
autorestart: true,
max_restarts: 10,
min_uptime: "10s",
},
],
};