import type { ExtensionAPI, ExtensionCommandContext, } from "@earendil-works/pi-coding-agent"; export interface RegisterYoloCommandOptions { isEnabled: () => boolean; setEnabled: (enabled: boolean, ctx: ExtensionCommandContext) => void; } export function setYoloStatus( ctx: Pick, enabled: boolean, ): void { ctx.ui.setStatus( "guardrails-yolo", enabled ? ctx.ui.theme.fg("warning", "⚠ YOLO") : undefined, ); } export function registerYoloCommand( pi: ExtensionAPI, options: RegisterYoloCommandOptions, ): void { pi.registerCommand("yolo", { description: "Disable all Guardrails blocking and filtering for this session (/yolo off to restore)", handler: async (args, ctx) => { const action = args.trim().toLowerCase(); if (action === "status") { const enabled = options.isEnabled(); setYoloStatus(ctx, enabled); ctx.ui.notify( `YOLO mode is ${enabled ? "enabled" : "disabled"}.`, enabled ? "warning" : "info", ); return; } if (action !== "" && action !== "on" && action !== "off") { ctx.ui.notify("Usage: /yolo [on|off|status]", "error"); return; } const enabled = action !== "off"; options.setEnabled(enabled, ctx); setYoloStatus(ctx, enabled); ctx.ui.notify( enabled ? "YOLO mode enabled for this session. Guardrails will not block or hide anything." : "YOLO mode disabled. Guardrails protections are active again.", enabled ? "warning" : "info", ); }, }); }