Files
oh-my-pi/packages/coding-agent/src/edit/read-file.ts
can1357 cbfdc0a212 feat(coding-agent): added notebook-aware .ipynb edit/read path helpers
- Added `.ipynb` detection and editable-cell conversion utilities, including merge/serialize helpers in `edit/notebook`.
- Rerouted hashline, patch, and replace edit flows, plus read/write paths, through notebook-aware helpers before persistence.
- Removed the dedicated `notebook` tool, its schema flags, renderer, and built-in registration/settings checks.
- Updated notebook read behavior, docs, and tests so `.ipynb` reads return editable `# %%` cells and edits reserialize to JSON.
2026-05-07 04:16:11 +02:00

26 lines
921 B
TypeScript

/**
* 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<string> {
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<string> {
if (isNotebookPath(absolutePath)) return serializeEditedNotebookText(absolutePath, path, content);
return content;
}