@adhdev/daemon-core 0.6.47 → 0.6.49

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.
@@ -37,6 +37,9 @@ export class StatusMonitor {
37
37
  private config: MonitorConfig;
38
38
  private lastAlertTime = new Map<string, number>();
39
39
  private generatingStartTimes = new Map<string, number>();
40
+ private longGeneratingAlerted = new Map<string, boolean>();
41
+ private lastProgressFingerprint = new Map<string, string>();
42
+ private lastProgressChangeAt = new Map<string, number>();
40
43
 
41
44
  constructor(config?: Partial<MonitorConfig>) {
42
45
  this.config = { ...DEFAULT_MONITOR_CONFIG, ...config };
@@ -56,7 +59,7 @@ export class StatusMonitor {
56
59
  * Check status transition → return notification event array.
57
60
  * Called from each onTick() or detectStatusTransition().
58
61
  */
59
- check(agentKey: string, status: string, now: number): MonitorEvent[] {
62
+ check(agentKey: string, status: string, now: number, progressFingerprint?: string): MonitorEvent[] {
60
63
  const events: MonitorEvent[] = [];
61
64
 
62
65
  // 1. Approval waiting notification
@@ -75,18 +78,31 @@ export class StatusMonitor {
75
78
  if (status === 'generating' || status === 'streaming') {
76
79
  if (!this.generatingStartTimes.has(agentKey)) {
77
80
  this.generatingStartTimes.set(agentKey, now);
81
+ this.longGeneratingAlerted.set(agentKey, false);
82
+ const initialFingerprint = progressFingerprint ?? '';
83
+ this.lastProgressFingerprint.set(agentKey, initialFingerprint);
84
+ this.lastProgressChangeAt.set(agentKey, now);
85
+ }
86
+ const currentFingerprint = progressFingerprint ?? '';
87
+ const previousFingerprint = this.lastProgressFingerprint.get(agentKey);
88
+ if (previousFingerprint !== currentFingerprint) {
89
+ this.lastProgressFingerprint.set(agentKey, currentFingerprint);
90
+ this.lastProgressChangeAt.set(agentKey, now);
91
+ this.longGeneratingAlerted.set(agentKey, false);
78
92
  }
79
93
  if (this.config.longGeneratingAlert) {
80
- const startedAt = this.generatingStartTimes.get(agentKey)!;
81
- const elapsedSec = Math.round((now - startedAt) / 1000);
82
- if (elapsedSec > this.config.longGeneratingThresholdSec) {
94
+ const progressChangedAt = this.lastProgressChangeAt.get(agentKey) || this.generatingStartTimes.get(agentKey)!;
95
+ const elapsedSec = Math.round((now - progressChangedAt) / 1000);
96
+ const alreadyAlerted = this.longGeneratingAlerted.get(agentKey) === true;
97
+ if (elapsedSec > this.config.longGeneratingThresholdSec && !alreadyAlerted) {
83
98
  if (this.shouldAlert(agentKey + ':long_gen', now)) {
99
+ this.longGeneratingAlerted.set(agentKey, true);
84
100
  events.push({
85
101
  type: 'monitor:long_generating',
86
102
  agentKey,
87
103
  elapsedSec,
88
104
  timestamp: now,
89
- message: `${agentKey} has been generating for ${Math.round(elapsedSec / 60)}min`,
105
+ message: `${agentKey} output appears stuck for ${Math.round(elapsedSec / 60)}min`,
90
106
  });
91
107
  }
92
108
  }
@@ -94,6 +110,9 @@ export class StatusMonitor {
94
110
  } else {
95
111
  // Reset timer when switching to non-generating status
96
112
  this.generatingStartTimes.delete(agentKey);
113
+ this.longGeneratingAlerted.delete(agentKey);
114
+ this.lastProgressFingerprint.delete(agentKey);
115
+ this.lastProgressChangeAt.delete(agentKey);
97
116
  }
98
117
 
99
118
  return events;
@@ -113,12 +132,18 @@ export class StatusMonitor {
113
132
  reset(agentKey?: string): void {
114
133
  if (agentKey) {
115
134
  this.generatingStartTimes.delete(agentKey);
135
+ this.longGeneratingAlerted.delete(agentKey);
136
+ this.lastProgressFingerprint.delete(agentKey);
137
+ this.lastProgressChangeAt.delete(agentKey);
116
138
  // Delete all cooldowns for this key
117
139
  for (const k of this.lastAlertTime.keys()) {
118
140
  if (k.startsWith(agentKey)) this.lastAlertTime.delete(k);
119
141
  }
120
142
  } else {
121
143
  this.generatingStartTimes.clear();
144
+ this.longGeneratingAlerted.clear();
145
+ this.lastProgressFingerprint.clear();
146
+ this.lastProgressChangeAt.clear();
122
147
  this.lastAlertTime.clear();
123
148
  }
124
149
  }