@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
36 lines • 1.37 kB
JavaScript
import { open, readFile, unlink, writeFile } from "node:fs/promises";
export const nodeCompactStorageIo = {
writeFile: (path, data) => writeFile(path, data, { flag: "wx", mode: 0o600 }),
readFile: async (path, range) => {
if (!range)
return readFile(path);
const handle = await open(path, "r");
try {
const { buffer, bytesRead } = await handle.read(Buffer.alloc(range.length), 0, range.length, range.offset);
return buffer.subarray(0, bytesRead);
}
finally {
await handle.close();
}
},
unlink: (path) => unlink(path),
};
/** Never throws: a host-supplied cause that cannot be described must not abort the failure report. */
export function describeCause(cause) {
try {
return cause instanceof Error ? cause.message : String(cause);
}
catch {
return "unprintable failure cause";
}
}
/** Committed storage that can no longer be read: a real error, never empty content. */
export class CompactStorageReadError extends Error {
constructor(operation, path, cause) {
super(`compact storage ${operation} failed for ${path}: ${describeCause(cause)}`, { cause });
this.name = "CompactStorageReadError";
this.operation = operation;
this.path = path;
}
}
//# sourceMappingURL=compact-storage-io.js.map