@yemi33/minions 0.1.477 → 0.1.478

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.477 (2026-04-07)
3
+ ## 0.1.478 (2026-04-07)
4
4
 
5
5
  ### Features
6
+ - Cache getStatus() JSON serialization and add mtime-based invalidation
6
7
  - Add mtime-based caching to getPrdInfo()
7
8
  - Optimize getAgentStatus() to read only head+tail of live-output.log
8
9
  - Fix unlocked metrics.json in lifecycle.js post-merge hook
package/dashboard.js CHANGED
@@ -264,20 +264,59 @@ function parsePinnedEntries(content) {
264
264
  }
265
265
 
266
266
  let _statusCache = null;
267
+ let _statusCacheJson = null; // cached JSON.stringify(_statusCache) — avoids double-serialization for SSE
267
268
  let _statusCacheTs = 0;
268
269
  const STATUS_CACHE_TTL = 10000; // 10s — reduces expensive aggregation frequency; mutations call invalidateStatusCache()
269
270
  const _statusStreamClients = new Set();
270
271
  let _statusPushTimer = null;
271
272
  let _lastStatusHash = '';
272
273
 
274
+ // mtime-based cache invalidation — skip full rebuild if no tracked files changed
275
+ const _mtimeTrackedFiles = () => {
276
+ const files = [
277
+ path.join(ENGINE_DIR, 'dispatch.json'),
278
+ path.join(ENGINE_DIR, 'control.json'),
279
+ path.join(ENGINE_DIR, 'log.json'),
280
+ path.join(ENGINE_DIR, 'metrics.json'),
281
+ ];
282
+ // Add per-project work-items.json
283
+ for (const p of PROJECTS) {
284
+ if (p.localPath) files.push(path.join(p.localPath, '.minions', 'work-items.json'));
285
+ }
286
+ // Central work-items.json
287
+ files.push(path.join(MINIONS_DIR, 'work-items.json'));
288
+ return files;
289
+ };
290
+ let _lastMtimes = {}; // { filePath: mtimeMs }
291
+
292
+ function _getMtimes() {
293
+ const result = {};
294
+ for (const fp of _mtimeTrackedFiles()) {
295
+ try { result[fp] = fs.statSync(fp).mtimeMs; } catch { result[fp] = 0; }
296
+ }
297
+ return result;
298
+ }
299
+
300
+ function _mtimesChanged(prev, curr) {
301
+ for (const fp of Object.keys(curr)) {
302
+ if (prev[fp] !== curr[fp]) return true;
303
+ }
304
+ // Also check if keys differ (new files appeared)
305
+ for (const fp of Object.keys(prev)) {
306
+ if (!(fp in curr)) return true;
307
+ }
308
+ return false;
309
+ }
310
+
273
311
  function invalidateStatusCache() {
274
312
  _statusCache = null;
313
+ _statusCacheJson = null;
275
314
  // Push to SSE clients (debounced 500ms to avoid flooding during batch mutations)
276
315
  if (_statusPushTimer) return;
277
316
  _statusPushTimer = setTimeout(() => {
278
317
  _statusPushTimer = null;
279
318
  if (_statusStreamClients.size === 0) return;
280
- const data = JSON.stringify(getStatus());
319
+ const data = getStatusJson();
281
320
  for (const res of _statusStreamClients) {
282
321
  try { res.write('data: ' + data + '\n\n'); } catch { _statusStreamClients.delete(res); }
283
322
  }
@@ -286,7 +325,11 @@ function invalidateStatusCache() {
286
325
 
287
326
  function getStatus() {
288
327
  const now = Date.now();
289
- if (_statusCache && (now - _statusCacheTs) < STATUS_CACHE_TTL) return _statusCache;
328
+ if (_statusCache && (now - _statusCacheTs) < STATUS_CACHE_TTL) {
329
+ // Within TTL — check mtimes for early return (skip full rebuild if nothing changed)
330
+ const currMtimes = _getMtimes();
331
+ if (!_mtimesChanged(_lastMtimes, currMtimes)) return _statusCache;
332
+ }
290
333
 
291
334
  // Reload config on each cache miss — picks up external changes (minions init, minions add)
292
335
  reloadConfig();
@@ -352,17 +395,27 @@ function getStatus() {
352
395
  timestamp: new Date().toISOString(),
353
396
  };
354
397
  _statusCacheTs = now;
398
+ _statusCacheJson = null; // invalidate cached JSON — will be lazily rebuilt by getStatusJson()
399
+ _lastMtimes = _getMtimes();
355
400
  return _statusCache;
356
401
  }
357
402
 
403
+ /** Return cached JSON string of status — single stringify, reused by SSE and /api/status */
404
+ function getStatusJson() {
405
+ getStatus(); // ensure _statusCache is fresh
406
+ if (!_statusCacheJson) {
407
+ _statusCacheJson = JSON.stringify(_statusCache);
408
+ }
409
+ return _statusCacheJson;
410
+ }
411
+
358
412
  // Periodic push for engine-driven changes (dispatch.json, control.json) that bypass invalidateStatusCache
359
413
  setInterval(() => {
360
414
  if (_statusStreamClients.size === 0) return;
361
- const status = getStatus();
362
- const hash = require('crypto').createHash('md5').update(JSON.stringify(status)).digest('hex');
415
+ const data = getStatusJson();
416
+ const hash = require('crypto').createHash('md5').update(data).digest('hex');
363
417
  if (hash === _lastStatusHash) return;
364
418
  _lastStatusHash = hash;
365
- const data = JSON.stringify(status);
366
419
  for (const res of _statusStreamClients) {
367
420
  try { res.write('data: ' + data + '\n\n'); } catch { _statusStreamClients.delete(res); }
368
421
  }
@@ -3500,7 +3553,18 @@ What would you like to discuss or change? When you're happy, say "approve" and I
3500
3553
 
3501
3554
  async function handleStatus(req, res) {
3502
3555
  try {
3503
- return jsonReply(res, 200, getStatus(), req);
3556
+ // Use pre-serialized JSON to avoid double-stringify in jsonReply
3557
+ const json = getStatusJson();
3558
+ res.setHeader('Content-Type', 'application/json');
3559
+ res.setHeader('Access-Control-Allow-Origin', '*');
3560
+ res.statusCode = 200;
3561
+ const ae = req && req.headers && req.headers['accept-encoding'] || '';
3562
+ if (ae.includes('gzip') && json.length > 1024) {
3563
+ res.setHeader('Content-Encoding', 'gzip');
3564
+ res.end(zlib.gzipSync(json));
3565
+ } else {
3566
+ res.end(json);
3567
+ }
3504
3568
  } catch (e) {
3505
3569
  return jsonReply(res, 500, { error: e.message }, req);
3506
3570
  }
@@ -3548,7 +3612,7 @@ What would you like to discuss or change? When you're happy, say "approve" and I
3548
3612
  { method: 'GET', path: '/api/status', desc: 'Full dashboard status snapshot (agents, PRDs, work items, dispatch, etc.)', handler: handleStatus },
3549
3613
  { method: 'GET', path: '/api/status-stream', desc: 'SSE stream of real-time status updates', handler: (req, res) => {
3550
3614
  res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive' });
3551
- res.write('data: ' + JSON.stringify(getStatus()) + '\n\n');
3615
+ res.write('data: ' + getStatusJson() + '\n\n');
3552
3616
  _statusStreamClients.add(res);
3553
3617
  req.on('close', () => _statusStreamClients.delete(res));
3554
3618
  }},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yemi33/minions",
3
- "version": "0.1.477",
3
+ "version": "0.1.478",
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"