| 26 | } |
| 27 | |
| 28 | export async function assert(sessionID: string, filepath: string) { |
| 29 | const time = get(sessionID, filepath) |
| 30 | if (!time) throw new Error(`You must read the file ${filepath} before overwriting it. Use the Read tool first`) |
| 31 | const stats = await Bun.file(filepath).stat() |
| 32 | if (stats.mtime.getTime() > time.getTime()) { |
| 33 | throw new Error( |
| 34 | `File ${filepath} has been modified since it was last read.\nLast modification: ${stats.mtime.toISOString()}\nLast read: ${time.toISOString()}\n\nPlease read the file again before modifying it.`, |
| 35 | ) |
| 36 | } |
| 37 | } |
| 38 | } |