clementine-agent 1.0.84 → 1.0.85

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.
@@ -1084,6 +1084,7 @@ function getAgentHeartbeats() {
1084
1084
  silentTickCount: Number(state.silentTickCount ?? 0),
1085
1085
  fingerprint: state.fingerprint ?? '',
1086
1086
  lastSignalSummary: state.lastSignalSummary ?? null,
1087
+ lastTickKind: state.lastTickKind ?? null,
1087
1088
  lastTickAgoMs: lastTickMs ? now - lastTickMs : null,
1088
1089
  nextCheckInMs: nextCheckMs ? nextCheckMs - now : null,
1089
1090
  isDue: nextCheckMs > 0 && nextCheckMs <= now,
@@ -8977,6 +8978,26 @@ if('serviceWorker' in navigator){navigator.serviceWorker.getRegistrations().then
8977
8978
  .desk-kpi-strip .dss-icon { font-size: 12px; opacity: 0.7; }
8978
8979
  .desk-kpi-strip .dss-val { font-weight: 700; color: var(--accent); }
8979
8980
 
8981
+ /* ── Heartbeat Strip ────────────── */
8982
+ .desk-hb-strip {
8983
+ display: flex;
8984
+ justify-content: center;
8985
+ gap: 6px;
8986
+ padding: 2px 12px;
8987
+ font-size: 10px;
8988
+ color: var(--text-muted);
8989
+ min-height: 0;
8990
+ }
8991
+ .desk-hb-strip:empty { display: none; }
8992
+ .desk-hb-strip .dss-item {
8993
+ display: flex;
8994
+ align-items: center;
8995
+ gap: 4px;
8996
+ white-space: nowrap;
8997
+ }
8998
+ .desk-hb-strip .dss-icon { font-size: 11px; opacity: 0.85; }
8999
+ .desk-hb-strip .dss-val { font-weight: 600; color: var(--text-secondary); }
9000
+
8980
9001
  /* ── Health Badge ──────────────────── */
8981
9002
  .desk-health-badge {
8982
9003
  display: none;
@@ -17272,6 +17293,9 @@ async function refreshTeam() {
17272
17293
  '</details>';
17273
17294
  }
17274
17295
 
17296
+ // Heartbeat strip — last/next tick, populated async from /api/agent-heartbeats
17297
+ var hbStrip = '<div class="desk-hb-strip" id="hb-' + a.slug + '"></div>';
17298
+
17275
17299
  // SDR KPI strip (fetched async, populated by data attribute)
17276
17300
  var kpiStrip = '<div class="desk-kpi-strip" id="kpi-' + a.slug + '"></div>';
17277
17301
 
@@ -17299,6 +17323,7 @@ async function refreshTeam() {
17299
17323
  (actions ? '<div class="desk-actions">' + actions + '</div>' : '') +
17300
17324
  '</div>' +
17301
17325
  statsStrip +
17326
+ hbStrip +
17302
17327
  kpiStrip +
17303
17328
  cronDetails +
17304
17329
  '</div>';
@@ -17312,6 +17337,54 @@ async function refreshTeam() {
17312
17337
 
17313
17338
  grid.innerHTML = cards.join('');
17314
17339
 
17340
+ // Heartbeat strip — single batch fetch, populate per-agent (avoids N requests).
17341
+ apiFetch('/api/agent-heartbeats').then(function(r) { return r.json(); }).then(function(hbList) {
17342
+ if (!Array.isArray(hbList)) return;
17343
+ var byAgent = {};
17344
+ for (var i = 0; i < hbList.length; i++) byAgent[hbList[i].slug] = hbList[i];
17345
+ agents.forEach(function(a) {
17346
+ var hb = byAgent[a.slug];
17347
+ var el = document.getElementById('hb-' + a.slug);
17348
+ if (!el || !hb) return;
17349
+ // "in 12 min" / "due now" / "10s ago tick"
17350
+ var nextLabel;
17351
+ if (hb.isDue) {
17352
+ nextLabel = 'due now';
17353
+ } else if (typeof hb.nextCheckInMs === 'number') {
17354
+ var mins = Math.max(1, Math.round(hb.nextCheckInMs / 60000));
17355
+ nextLabel = mins < 60 ? 'in ' + mins + 'm' : 'in ' + Math.floor(mins / 60) + 'h';
17356
+ } else {
17357
+ nextLabel = '—';
17358
+ }
17359
+ var lastLabel = hb.lastTickAt ? fmtTimeAgo(hb.lastTickAt) : 'never';
17360
+ // Tick-kind icon — small visual signal
17361
+ var kindIcon = '';
17362
+ var kindTitle = '';
17363
+ switch (hb.lastSignalSummary && hb.lastSignalSummary.indexOf('llm tick error') === 0
17364
+ ? 'error' : '') {
17365
+ case 'error':
17366
+ kindIcon = '⚠'; kindTitle = 'Last tick errored — fell back to quiet cadence';
17367
+ break;
17368
+ }
17369
+ // Use a literal field if available — backend exposes lastTickKind via state file
17370
+ // (we read it through getAgentHeartbeats which preserves the field)
17371
+ if (!kindIcon) {
17372
+ switch (hb.lastTickKind) {
17373
+ case 'acted': kindIcon = '⚡'; kindTitle = 'Active — agent took action last tick'; break;
17374
+ case 'quiet': kindIcon = '◌'; kindTitle = 'Quiet — agent saw signals but had nothing to do'; break;
17375
+ case 'silent': kindIcon = '·'; kindTitle = 'Silent — fingerprint unchanged, backing off'; break;
17376
+ case 'override': kindIcon = '◇'; kindTitle = 'Override — cadence set explicitly by the agent'; break;
17377
+ default: kindIcon = '·'; kindTitle = 'No tick recorded yet';
17378
+ }
17379
+ }
17380
+ el.innerHTML =
17381
+ '<span class="dss-item" title="' + kindTitle + '">' +
17382
+ '<span class="dss-icon">' + kindIcon + '</span> ' +
17383
+ '<span class="dss-val">' + lastLabel + '</span> · next ' + nextLabel +
17384
+ '</span>';
17385
+ });
17386
+ }).catch(function() { /* heartbeat endpoint missing or daemon old — silently skip */ });
17387
+
17315
17388
  // Async-fetch KPIs and health for each agent
17316
17389
  agents.forEach(function(a) {
17317
17390
  // KPI strip
@@ -10,7 +10,7 @@
10
10
  * out. Per-agent failures are caught so one buggy agent can't crash the
11
11
  * daemon or stall others.
12
12
  */
13
- import { existsSync, mkdirSync, watch } from 'node:fs';
13
+ import { existsSync, mkdirSync, readFileSync, unlinkSync, watch } from 'node:fs';
14
14
  import path from 'node:path';
15
15
  import pino from 'pino';
16
16
  import { AGENTS_DIR, BASE_DIR } from '../config.js';
@@ -107,22 +107,15 @@ export class AgentHeartbeatManager {
107
107
  if (!filename.endsWith('.json'))
108
108
  return;
109
109
  const slug = filename.replace(/\.json$/, '');
110
- // Consume the sentinel + wake the agent
111
- try {
112
- // Use unlinkSync via require to keep top-level import surface tight
113
- // (already imported existsSync — we use it before unlink to be safe)
114
- const sentinelPath = path.join(wakeDir, filename);
115
- if (existsSync(sentinelPath)) {
116
- // best-effort: import unlinkSync inline
117
- // eslint-disable-next-line @typescript-eslint/no-var-requires
118
- const fs = require('node:fs');
119
- try {
120
- fs.unlinkSync(sentinelPath);
121
- }
122
- catch { /* ignore */ }
110
+ // Consume the sentinel + wake the agent. Best-effort delete so the
111
+ // same sentinel can't fire repeatedly.
112
+ const sentinelPath = path.join(wakeDir, filename);
113
+ if (existsSync(sentinelPath)) {
114
+ try {
115
+ unlinkSync(sentinelPath);
123
116
  }
117
+ catch { /* ignore */ }
124
118
  }
125
- catch { /* non-fatal */ }
126
119
  this.scheduleWake(slug, 'wake-sentinel');
127
120
  });
128
121
  }
@@ -197,9 +190,7 @@ export class AgentHeartbeatManager {
197
190
  const triggerPath = path.join(BASE_DIR, 'cron', 'goal-triggers', filename);
198
191
  if (!existsSync(triggerPath))
199
192
  return; // file was already consumed by cron-scheduler
200
- // eslint-disable-next-line @typescript-eslint/no-var-requires
201
- const fs = require('node:fs');
202
- const trigger = JSON.parse(fs.readFileSync(triggerPath, 'utf-8'));
193
+ const trigger = JSON.parse(readFileSync(triggerPath, 'utf-8'));
203
194
  if (!trigger.goalId)
204
195
  return;
205
196
  const lookup = listAllGoals().find((g) => g.goal && g.goal.id === trigger.goalId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clementine-agent",
3
- "version": "1.0.84",
3
+ "version": "1.0.85",
4
4
  "description": "Clementine — Personal AI Assistant (TypeScript)",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",