UNPKG

logggai

Version:

AI-powered CLI for transforming your development work into professional content

82 lines 3.29 kB
"use strict"; // Logggai Auto-Sync Daemon // Watches for unsynced commits and triggers grouped sync automatically. Object.defineProperty(exports, "__esModule", { value: true }); const path = require("path"); const fs = require("fs"); // Log de debug pour tout démarrage du process daemon (même si tout le reste plante) fs.appendFileSync('daemon-debug.log', `[${new Date().toISOString()}] Daemon process started in ${process.cwd()}\n`); const project_1 = require("./lib/project"); const sync_1 = require("./commands/sync"); // @ts-ignore: No types for node-notifier const notifier = require("node-notifier"); const LOG_FILE = path.join(process.cwd(), '.logggai-daemon.log'); const PID_FILE = path.join(process.cwd(), '.logggai-daemon.pid'); function log(msg) { const line = `[${new Date().toISOString()}] ${msg}\n`; fs.appendFileSync(LOG_FILE, line); } function writePid() { fs.writeFileSync(PID_FILE, process.pid.toString()); } function removePid() { if (fs.existsSync(PID_FILE)) fs.unlinkSync(PID_FILE); } async function daemonLoop() { log('Logggai Auto-Sync Daemon started.'); writePid(); let mappingHelpLogged = false; while (true) { try { log('Daemon loop: checking project config...'); const projectConfig = (0, project_1.readProjectConfig)(); if (!projectConfig) { log('No .logggai-project.json mapping found in ' + process.cwd() + '. Daemon will wait and retry.'); if (!mappingHelpLogged) { log('Tip: Run `logggai project` in this folder to initialize the mapping and enable auto-sync.'); mappingHelpLogged = true; } } else { mappingHelpLogged = false; log('Mapping loaded: ' + JSON.stringify(projectConfig)); const { getCommitsSince } = require('./lib/git'); const unsyncedCommits = await getCommitsSince(projectConfig.lastSyncedCommit || null); log(`Found ${unsyncedCommits.length} unsynced commits.`); const shouldSync = unsyncedCommits.length >= 20; log(`Should sync? ${shouldSync}`); if (shouldSync) { log('Auto-sync triggered.'); await (0, sync_1.syncCommand)({ nonInteractive: true }); log('Sync command finished. Sending notification...'); notifier.notify({ title: 'Logggai Auto-Sync', message: 'A grouped sync was triggered automatically (threshold reached).', wait: false }); log('Notification sent.'); } } } catch (err) { log('Error: ' + (err && err.stack ? err.stack : err)); } await new Promise(res => setTimeout(res, 2 * 60 * 1000)); // 2 min } } process.on('SIGINT', () => { log('Daemon stopped by SIGINT.'); removePid(); process.exit(0); }); process.on('SIGTERM', () => { log('Daemon stopped by SIGTERM.'); removePid(); process.exit(0); }); // Start the daemon (async () => { await daemonLoop(); })(); //# sourceMappingURL=autosync-daemon.js.map