UNPKG

@stackmemoryai/stackmemory

Version:

Project-scoped memory for AI coding tools. Durable context across sessions with MCP integration, frames, smart retrieval, Claude Code skills, and automatic hooks.

50 lines (49 loc) 1.16 kB
import { fileURLToPath as __fileURLToPath } from 'url'; import { dirname as __pathDirname } from 'path'; const __filename = __fileURLToPath(import.meta.url); const __dirname = __pathDirname(__filename); import { writeFileSync, mkdirSync, chmodSync, existsSync, renameSync, unlinkSync } from "fs"; import { dirname, join } from "path"; import { randomBytes } from "crypto"; function writeFileSecure(filePath, data) { const dir = dirname(filePath); if (!existsSync(dir)) { mkdirSync(dir, { recursive: true, mode: 448 }); } const tempPath = join(dir, `.tmp-${randomBytes(8).toString("hex")}`); try { writeFileSync(tempPath, data); chmodSync(tempPath, 384); renameSync(tempPath, filePath); } catch (error) { try { if (existsSync(tempPath)) { unlinkSync(tempPath); } } catch { } throw error; } } function ensureSecureDir(dirPath) { if (!existsSync(dirPath)) { mkdirSync(dirPath, { recursive: true, mode: 448 }); } else { try { chmodSync(dirPath, 448); } catch { } } } export { ensureSecureDir, writeFileSecure }; //# sourceMappingURL=secure-fs.js.map