Files
2026-08-11 03:53:15 +00:00

60 lines
2.2 KiB
TypeScript

import { resolve } from "node:path";
import { runKillDrill } from "../src/kill-test";
import { makeLiveKillDrillPorts } from "../src/kill-test-live";
const LIVE_CONFIRMATION = "--confirm-live-gateway-kill";
function required(name: string): string {
const value = process.env[name]?.trim();
if (!value) throw new Error(`${name} is required`);
return value;
}
if (!process.argv.includes(LIVE_CONFIRMATION)) {
console.error([
"Refusing to run the real gateway kill drill without explicit confirmation.",
"This script closes the configured gateway pane and sends a real Telegram DM.",
`Run again with ${LIVE_CONFIRMATION} during the supervised cutover sitting.`,
].join("\n"));
process.exit(2);
}
const date = new Date().toISOString().slice(0, 10);
const ports = makeLiveKillDrillPorts({
agentTarget: required("GATEWAY_AGENT_TARGET"),
successorBriefPath: resolve(required("GATEWAY_SUCCESSOR_BRIEF_PATH")),
redisUrl: process.env.REDIS_URL?.trim(),
heartbeatKey: process.env.GATEWAY_HEARTBEAT_KEY?.trim(),
herdrSession: process.env.GATEWAY_HERDR_SESSION?.trim(),
receiptPath: process.env.GATEWAY_KILL_DRILL_RECEIPT_PATH?.trim()
?? "/tmp/joelclaw/agent-comms-kill-drill.jsonl",
});
try {
const result = await runKillDrill(ports, {
date,
heartbeatTtlMs: Number(process.env.GATEWAY_HEARTBEAT_TTL_MS ?? 60_000),
assertionTimeoutMs: Number(process.env.GATEWAY_KILL_DRILL_TIMEOUT_MS ?? 120_000),
recoveryTimeoutMs: Number(process.env.GATEWAY_KILL_DRILL_RECOVERY_TIMEOUT_MS ?? 420_000),
pollIntervalMs: Number(process.env.GATEWAY_KILL_DRILL_POLL_MS ?? 1_000),
});
console.log(JSON.stringify({ ok: true, command: "agent-comms kill-drill", result }, null, 2));
} catch (error) {
const chain: string[] = [];
let current: unknown = error;
while (current) {
chain.push(current instanceof Error ? `${current.name}: ${current.message}` : String(current));
current = current instanceof Error ? current.cause : undefined;
}
console.error(JSON.stringify({
ok: false,
command: "agent-comms kill-drill",
error: chain.join(" | cause: "),
stack: error instanceof Error ? error.stack?.split("\n").slice(0, 8) : undefined,
}, null, 2));
process.exitCode = 1;
} finally {
await ports.close();
}