import { editAutoGeneratedMessage } from "@oh-my-pi/pi-natives"; import { settings as globalSettings, isSettingsInitialized, type Settings } from "../config/settings"; import { ToolError } from "@oh-my-pi/pi-tui/tools/tool-errors"; import { cfgEditBlockAutoGenerated } from "../edit/settings"; function shouldBlockAutoGeneratedFiles(activeSettings?: Settings): boolean { if (activeSettings) return cfgEditBlockAutoGenerated.get(activeSettings); if (isSettingsInitialized()) return cfgEditBlockAutoGenerated.get(globalSettings); return cfgEditBlockAutoGenerated.default; } /** Throw when the native generated-file detector rejects this path. */ export async function assertEditableFile( absolutePath: string, displayPath?: string, activeSettings?: Settings, ): Promise { if (!shouldBlockAutoGeneratedFiles(activeSettings)) return; const message = editAutoGeneratedMessage(absolutePath, displayPath ?? absolutePath); if (message) throw new ToolError(message); }