@yemi33/minions 0.1.478 → 0.1.479

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # Changelog
2
2
 
3
- ## 0.1.478 (2026-04-07)
3
+ ## 0.1.479 (2026-04-07)
4
4
 
5
5
  ### Features
6
+ - Buffer log() writes to reduce lock contention
6
7
  - Cache getStatus() JSON serialization and add mtime-based invalidation
7
8
  - Add mtime-based caching to getPrdInfo()
8
9
  - Optimize getAgentStatus() to read only head+tail of live-output.log
package/engine/cli.js CHANGED
@@ -391,6 +391,7 @@ const commands = {
391
391
  if (e.activeProcesses.size === 0) {
392
392
  safeWrite(CONTROL_PATH, { state: 'stopped', stopped_at: e.ts() });
393
393
  e.log('info', 'Graceful shutdown complete (no active agents)');
394
+ shared.flushLogs(); // drain buffered log entries before exit
394
395
  console.log('No active agents — stopped.');
395
396
  process.exit(0);
396
397
  }
@@ -404,6 +405,7 @@ const commands = {
404
405
  clearInterval(poll);
405
406
  safeWrite(CONTROL_PATH, { state: 'stopped', stopped_at: e.ts() });
406
407
  e.log('info', 'Graceful shutdown complete (all agents finished)');
408
+ shared.flushLogs(); // drain buffered log entries before exit
407
409
  console.log('All agents finished — stopped.');
408
410
  process.exit(0);
409
411
  }
@@ -411,6 +413,7 @@ const commands = {
411
413
  clearInterval(poll);
412
414
  safeWrite(CONTROL_PATH, { state: 'stopped', stopped_at: e.ts() });
413
415
  e.log('warn', `Graceful shutdown timed out after ${timeout / 1000}s with ${e.activeProcesses.size} agent(s) still active`);
416
+ shared.flushLogs(); // drain buffered log entries before exit
414
417
  console.log(`Shutdown timeout (${timeout / 1000}s) — force exiting with ${e.activeProcesses.size} agent(s) still running.`);
415
418
  process.exit(1);
416
419
  }
package/engine/shared.js CHANGED
@@ -18,20 +18,56 @@ function ts() { return new Date().toISOString(); }
18
18
  function logTs() { return new Date().toLocaleTimeString(); }
19
19
  function dateStamp() { return new Date().toISOString().slice(0, 10); }
20
20
 
21
+ // ── Log Buffering ──────────────────────────────────────────────────────────
22
+ // Buffer log entries in memory and flush to disk periodically to reduce lock
23
+ // contention (~139 calls/tick → 1 lock acquisition per flush).
24
+ const _logBuffer = [];
25
+ let _logFlushTimer = null;
26
+
21
27
  function log(level, msg, meta = {}) {
22
28
  const entry = { timestamp: ts(), level, message: msg, ...meta };
29
+ // Console output remains immediate
23
30
  console.log(`[${logTs()}] [${level}] ${msg}`);
24
31
 
32
+ _logBuffer.push(entry);
33
+
34
+ // Start the flush timer lazily on first buffered entry
35
+ if (!_logFlushTimer) {
36
+ _logFlushTimer = setInterval(() => {
37
+ _flushLogBuffer();
38
+ }, ENGINE_DEFAULTS.logFlushInterval);
39
+ // Unref so the timer doesn't keep the process alive during shutdown
40
+ if (_logFlushTimer.unref) _logFlushTimer.unref();
41
+ }
42
+
43
+ // Flush immediately when buffer exceeds threshold
44
+ if (_logBuffer.length >= ENGINE_DEFAULTS.logBufferSize) {
45
+ _flushLogBuffer();
46
+ }
47
+ }
48
+
49
+ function _flushLogBuffer() {
50
+ if (_logBuffer.length === 0) return;
51
+ const entries = _logBuffer.splice(0);
25
52
  try {
26
53
  mutateJsonFileLocked(LOG_PATH, (logData) => {
27
54
  if (!Array.isArray(logData)) logData = logData?.entries || [];
28
- logData.push(entry);
55
+ logData.push(...entries);
29
56
  if (logData.length >= 2500) logData.splice(0, logData.length - 2000);
30
57
  return logData;
31
58
  }, { defaultValue: [] });
32
59
  } catch { /* logging should never crash the caller */ }
33
60
  }
34
61
 
62
+ /** Flush buffered log entries to disk. Call during graceful shutdown to drain the buffer. */
63
+ function flushLogs() {
64
+ _flushLogBuffer();
65
+ if (_logFlushTimer) {
66
+ clearInterval(_logFlushTimer);
67
+ _logFlushTimer = null;
68
+ }
69
+ }
70
+
35
71
  // ── File I/O ─────────────────────────────────────────────────────────────────
36
72
 
37
73
  function safeRead(p) {
@@ -441,6 +477,8 @@ const ENGINE_DEFAULTS = {
441
477
  pipelineApiRetries: 2, // max attempts for pipeline API calls
442
478
  pipelineApiRetryDelay: 2000, // ms delay between pipeline API retries
443
479
  versionCheckInterval: 3600000, // 1 hour — how often to check npm for updates (ms)
480
+ logFlushInterval: 5000, // 5s — how often to flush buffered log entries to disk
481
+ logBufferSize: 50, // flush immediately when buffer exceeds this many entries
444
482
  };
445
483
 
446
484
  // ─── Status & Type Constants ─────────────────────────────────────────────────
@@ -729,5 +767,7 @@ module.exports = {
729
767
  killGracefully,
730
768
  killImmediate,
731
769
  LOCK_STALE_MS,
770
+ flushLogs,
771
+ _logBuffer, // exported for testing
732
772
  };
733
773
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yemi33/minions",
3
- "version": "0.1.478",
3
+ "version": "0.1.479",
4
4
  "description": "Multi-agent AI dev team that runs from ~/.minions/ — five autonomous agents share a single engine, dashboard, and knowledge base",
5
5
  "bin": {
6
6
  "minions": "bin/minions.js"