import { Command } from 'commander'; import chalk from 'chalk'; import { performOverride, getSessionState } from '../utils/governance.js'; import { getApiKey, getProjectId, getApiUrl } from '../utils/config.js'; import axios from 'axios'; export function createOverrideCommand() { const override = new Command('override'); override .description('Emergency Override for Governance Soft Locks') .argument('', 'ID of the violation to override (or "all")') .requiredOption('-r, --reason ', 'Description of why this override is necessary') .action(async (violationId, options) => { const { reason } = options; console.log(chalk.bold(`\nšŸ”“ Initiating Governance Override Protocol...`)); const session = await getSessionState(process.cwd()); if (session.status !== 'SOFT_LOCK') { console.log(chalk.yellow(' Info: Session is not currently locked.')); return; // Not locked, but maybe we still want to log the "intent"? } console.log(chalk.dim(` Active Violation: ${session.active_violation}`)); console.log(chalk.dim(` Reason Provided: "${reason}"`)); // Perform Local Unlock const success = await performOverride(violationId, reason, process.cwd()); if (success) { console.log(chalk.green(` āœ… Session UNLOCKED.`)); console.log(chalk.dim(` This event has been logged to the Mission Report.`)); // Optional: Notify Cloud about the Override (Audit Trail) try { const projectId = getProjectId(); if (projectId) { const apiUrl = getApiUrl(); const apiKey = getApiKey(); await axios.post(`${apiUrl}/api/v1/execution-logs`, { project_id: projectId, task_id: 'OVERRIDE-' + Date.now(), task_title: `Governance Override: ${violationId}`, status: 'COMPLETED', execution_summary: `Manual override executed. Reason: ${reason}`, agent_role: 'SUPERVISOR' // Override is a supervisor action }, { headers: { Authorization: `Bearer ${apiKey}` } }); console.log(chalk.dim(` ☁ Audit log synced to Cloud.`)); } } catch (e: any) { console.log(chalk.dim(` (Cloud audit sync failed: ${e.message})`)); } } else { console.log(chalk.red(` šŸ›‘ Override Failed. Check project configuration.`)); } }); return override; }