ktg-plugin-marketplace/plugins/ms-ai-architect/scripts/kb-update/lib
Kjell Tore Guttormsen 4a615b10ce feat(ms-ai-architect): add lib/atomic-write for crash-safe state files [skip-docs]
Foundation lib for status-fil + lock-fil writes in v1.12.0 cron rewrite.
Pattern: writeFileSync to <path>.tmp.<pid>.<random> then renameSync to
target. Defends against half-written files; readers either see the
previous version or the new one, never a partial.

- atomicWriteSync(path, content) — string or Buffer
- atomicWriteJson(path, obj) — 2-space indent, trailing newline
- Windows EEXIST/EPERM defensive fallback (unlink target + rename)
- Best-effort tmp cleanup on writeFileSync failure
- crypto.randomInt(0, 2**32) two-arg form (unambiguous across Node)

9/9 tests pass including 50-way concurrent-write fuzzer (async-aware
withTmp helper).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-05 10:32:13 +02:00
..
atomic-write.mjs feat(ms-ai-architect): add lib/atomic-write for crash-safe state files [skip-docs] 2026-05-05 10:32:13 +02:00
cross-platform-paths.mjs feat(ms-ai-architect): add lib/cross-platform-paths for cache/log/state/backup dirs [skip-docs] 2026-05-05 10:30:31 +02:00
registry-io.mjs feat(ms-ai-architect): sitemap-based KB change detection system 2026-04-09 21:19:51 +02:00
sitemap-stream.mjs feat(ms-ai-architect): sitemap-based KB change detection system 2026-04-09 21:19:51 +02:00
url-normalize.mjs feat(ms-ai-architect): sitemap-based KB change detection system 2026-04-09 21:19:51 +02:00