// ledger.js const fs = require('fs'); const path = require('path'); const LEDGER_DIR = path.join(__dirname, 'ledger'); function ensureLedgerDir() { if (!fs.existsSync(LEDGER_DIR)) { fs.mkdirSync(LEDGER_DIR); } } function timestampForFilename() { const now = new Date(); const iso = now.toISOString(); // e.g. 2026-06-28T16:12:34.567Z return iso.replace(/[:.]/g, '-'); } function writeLedgerEntry(entry) { ensureLedgerDir(); const filename = `${timestampForFilename()}.json`; const filepath = path.join(LEDGER_DIR, filename); const payload = { engineVersion: 'v0.2-ledger', createdAt: new Date().toISOString(), entry, }; fs.writeFileSync(filepath, JSON.stringify(payload, null, 2), 'utf8'); return filepath; } module.exports = { writeLedgerEntry };