diff --git a/src/agents/orchestrator.ts b/src/agents/orchestrator.ts index 77ab775..a7166c7 100644 --- a/src/agents/orchestrator.ts +++ b/src/agents/orchestrator.ts @@ -19,6 +19,7 @@ import { Specification, parseSpecification } from "../types/specification.js"; import { loadConfig, saveConfig, isCIAgentInitialized, initCIAgent } from "../core/config.js"; import { getAgent } from "./index.js"; import { IntelligenceBackend, BackendUnavailableError } from "../backends/types.js"; +import { registerEscalationProtocol } from "../cli/index.js"; import { execSync } from "node:child_process"; export interface GitAgentContext extends AgentContext { @@ -87,6 +88,7 @@ export class OrchestratorAgent extends BaseAgent { this.decisionEngine = new DecisionEngine(this.config, context.project_path, this.currentMilestone); this.escalationProtocol = new EscalationProtocol(this.config, context.project_path, this.currentMilestone); + registerEscalationProtocol(this.escalationProtocol); while (this.pipelineState.current_phase <= this.totalPhases) { this.log(`Processing phase ${this.pipelineState.current_phase} of ${this.totalPhases}`); diff --git a/src/cli/index.ts b/src/cli/index.ts index c0d05a1..448e979 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -19,6 +19,25 @@ import { createProjectsCommand, } from "./commands.js"; +let activeEscalationProtocol: { dispose(): void } | null = null; + +export function registerEscalationProtocol(protocol: { dispose(): void }): void { + activeEscalationProtocol = protocol; +} + +function gracefulShutdown(signal: string): void { + if (activeEscalationProtocol) { + try { + activeEscalationProtocol.dispose(); + } catch {} + activeEscalationProtocol = null; + } + process.exit(signal === "SIGINT" ? 130 : 143); +} + +process.on("SIGINT", () => gracefulShutdown("SIGINT")); +process.on("SIGTERM", () => gracefulShutdown("SIGTERM")); + const program = new Command(); program