{"version":3,"file":"atomic-file.d.ts","sourceRoot":"","sources":["../../src/utils/atomic-file.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAUpE","sourcesContent":["import { mkdirSync, renameSync, rmSync, writeFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\n\n/**\n * Write a file atomically: write to a unique temp file in the same directory,\n * then rename over the target. The same-directory temp keeps the rename on one\n * filesystem (rename across mounts is a non-atomic copy), so a reader can never\n * observe a torn, half-written file — it sees either the old content or the\n * new. Used for handshake files like a subagent's result.json, where a reader\n * (the parent pool) may race a writer that gets SIGKILLed mid-write.\n *\n * Throws on failure like writeFileSync; callers that treat persistence as\n * best-effort keep their own try/catch.\n */\nexport function writeFileAtomicSync(path: string, data: string): void {\n\tmkdirSync(dirname(path), { recursive: true });\n\tconst tempPath = join(dirname(path), `.${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}.tmp`);\n\ttry {\n\t\twriteFileSync(tempPath, data);\n\t\trenameSync(tempPath, path);\n\t} catch (error) {\n\t\trmSync(tempPath, { force: true });\n\t\tthrow error;\n\t}\n}\n"]}