import type { Fs } from './fs' // hooks 沙箱沒有 node:fs,改用引擎的 $.fs;它沒有 rename,所以不提供(writeAtomic 會直接覆寫) type EngineFs = { read(path: string): Promise write(path: string, text: string): Promise list(path?: string): Promise<{ name: string }[]> } export const engineFs = (fs: EngineFs): Fs => ({ async read(path) { try { return await fs.read(path) } catch { return null } }, write: (path, data) => fs.write(path, data), async list(dir) { try { return (await fs.list(dir)).map(e => e.name).filter(n => !n.endsWith('.tmp')).sort() } catch { return [] } }, })