/** * Shared file-read helper for edit-mode utilities. * * Reads a file via Bun and rethrows ENOENT as a user-facing "File not found" * error referencing the display path. */ import { isEnoent } from "@oh-my-pi/pi-utils"; import { isNotebookPath, readEditableNotebookText, serializeEditedNotebookText } from "./notebook"; export async function readEditFileText(absolutePath: string, path: string): Promise { try { if (isNotebookPath(absolutePath)) return await readEditableNotebookText(absolutePath, path); return await Bun.file(absolutePath).text(); } catch (error) { if (isEnoent(error)) { throw new Error(`File not found: ${path}`); } throw error; } } export async function serializeEditFileText(absolutePath: string, path: string, content: string): Promise { if (isNotebookPath(absolutePath)) return serializeEditedNotebookText(absolutePath, path, content); return content; }