export const GUARDRAILS_YOLO_ENTRY = "guardrails-yolo"; export const GUARDRAILS_INHERITED_YOLO_ENTRY = "guardrails-inherited-yolo"; export const GUARDRAILS_INHERITED_YOLO_ENV = "PI_GUARDRAILS_YOLO"; export function initialYoloMode(input: { reason: string; restored: boolean; inherited: boolean | undefined; isSubagent: boolean; }): boolean { if (input.isSubagent && input.inherited !== undefined) return input.inherited; return input.reason === "new" || input.reason === "fork" ? false : input.restored; } export function inheritedYoloMode( envValue = process.env[GUARDRAILS_INHERITED_YOLO_ENV], ): boolean | undefined { if (envValue === "1") return true; if (envValue === "0") return false; return undefined; } interface CustomEntryLike { type?: unknown; customType?: unknown; data?: unknown; } /** Resolve the latest YOLO choice on the active session branch. */ export function restoreYoloMode(entries: readonly unknown[]): boolean { let enabled = false; for (const candidate of entries) { if (!candidate || typeof candidate !== "object") continue; const entry = candidate as CustomEntryLike; if (entry.type !== "custom" || entry.customType !== GUARDRAILS_YOLO_ENTRY) { continue; } const data = entry.data as { enabled?: unknown } | undefined; if (typeof data?.enabled === "boolean") enabled = data.enabled; } return enabled; }