@adhdev/daemon-core 0.5.40 → 0.5.42
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/dist/index.d.ts +8 -0
- package/dist/index.js +41 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/config/config.ts +6 -0
- package/src/providers/ide-provider-instance.ts +42 -0
- package/src/providers/status-monitor.ts +15 -15
package/package.json
CHANGED
package/src/config/config.ts
CHANGED
|
@@ -30,6 +30,12 @@ export interface ADHDevConfig {
|
|
|
30
30
|
|
|
31
31
|
// User preferences
|
|
32
32
|
autoConnect: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated Not read at runtime. Notification preferences are now managed by:
|
|
35
|
+
* - Web UI layer: useNotificationPrefs (localStorage)
|
|
36
|
+
* - Daemon layer: per-provider settings (approvalAlert, longGeneratingAlert)
|
|
37
|
+
* Kept for backward config compat — will be removed in v0.7+.
|
|
38
|
+
*/
|
|
33
39
|
notifications: boolean;
|
|
34
40
|
|
|
35
41
|
// Auth
|
|
@@ -36,6 +36,7 @@ export class IdeProviderInstance implements ProviderInstance {
|
|
|
36
36
|
private tickBusy = false;
|
|
37
37
|
private monitor: StatusMonitor;
|
|
38
38
|
private historyWriter: ChatHistoryWriter;
|
|
39
|
+
private autoApproveBusy = false;
|
|
39
40
|
|
|
40
41
|
// IDE meta
|
|
41
42
|
private ideVersion: string = '';
|
|
@@ -361,6 +362,11 @@ export class IdeProviderInstance implements ProviderInstance {
|
|
|
361
362
|
this.lastAgentStatuses.set(agentKey, agentStatus);
|
|
362
363
|
}
|
|
363
364
|
|
|
365
|
+
// Auto-approve: when waiting_approval + settings.autoApprove → auto-click approve via CDP
|
|
366
|
+
if (agentStatus === 'waiting_approval' && this.settings.autoApprove && !this.autoApproveBusy) {
|
|
367
|
+
this.autoApproveViaScript(chatData);
|
|
368
|
+
}
|
|
369
|
+
|
|
364
370
|
// Monitor check (cooldown based notification)
|
|
365
371
|
const monitorEvents = this.monitor.check(agentKey, agentStatus, now);
|
|
366
372
|
for (const me of monitorEvents) {
|
|
@@ -384,4 +390,40 @@ export class IdeProviderInstance implements ProviderInstance {
|
|
|
384
390
|
updateCdp(cdp: InstanceContext['cdp']): void {
|
|
385
391
|
if (this.context) this.context.cdp = cdp;
|
|
386
392
|
}
|
|
393
|
+
|
|
394
|
+
// ─── Auto-approve via CDP script ────────────────────
|
|
395
|
+
|
|
396
|
+
private async autoApproveViaScript(_chatData: any): Promise<void> {
|
|
397
|
+
const cdp = this.context?.cdp;
|
|
398
|
+
if (!cdp?.isConnected) return;
|
|
399
|
+
|
|
400
|
+
// Check if provider has resolveAction script
|
|
401
|
+
const scriptFn = this.provider.scripts?.resolveAction;
|
|
402
|
+
if (typeof scriptFn !== 'function') {
|
|
403
|
+
LOG.debug('IdeInstance', `[IdeInstance:${this.type}] autoApprove: no resolveAction script available`);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
this.autoApproveBusy = true;
|
|
408
|
+
try {
|
|
409
|
+
const script = scriptFn({ action: 'approve', button: '', buttonText: '' });
|
|
410
|
+
if (!script) return;
|
|
411
|
+
|
|
412
|
+
LOG.info('IdeInstance', `[IdeInstance:${this.type}] autoApprove: executing resolveAction`);
|
|
413
|
+
const result = await cdp.evaluate(script, 10000);
|
|
414
|
+
LOG.info('IdeInstance', `[IdeInstance:${this.type}] autoApprove result: ${JSON.stringify(result)?.slice(0, 200)}`);
|
|
415
|
+
|
|
416
|
+
this.pushEvent({
|
|
417
|
+
event: 'agent:auto_approved',
|
|
418
|
+
chatTitle: _chatData?.title || this.provider.name,
|
|
419
|
+
timestamp: Date.now(),
|
|
420
|
+
ideType: this.type,
|
|
421
|
+
});
|
|
422
|
+
} catch (e: any) {
|
|
423
|
+
LOG.warn('IdeInstance', `[IdeInstance:${this.type}] autoApprove error: ${e?.message}`);
|
|
424
|
+
} finally {
|
|
425
|
+
// Debounce: prevent rapid re-approval for at least 500ms
|
|
426
|
+
setTimeout(() => { this.autoApproveBusy = false; }, 500);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
387
429
|
}
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* StatusMonitor —
|
|
2
|
+
* StatusMonitor — Status monitoring notification system
|
|
3
3
|
*
|
|
4
|
-
* Common across all Provider categories (IDE/Extension/CLI).
|
|
5
|
-
* -
|
|
4
|
+
* Common across all Provider categories (IDE/Extension/CLI/ACP).
|
|
5
|
+
* - Approval waiting (waiting_approval) notification
|
|
6
6
|
* - Notification when generating persists for extended duration
|
|
7
|
-
* -
|
|
7
|
+
* - All config toggleable via Provider Settings
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
export interface MonitorConfig {
|
|
11
11
|
/** Enable awaiting-approval notification */
|
|
12
12
|
approvalAlert: boolean;
|
|
13
|
-
/**
|
|
13
|
+
/** Prolonged generating notification enabled */
|
|
14
14
|
longGeneratingAlert: boolean;
|
|
15
15
|
/** Prolonged threshold (seconds) */
|
|
16
16
|
longGeneratingThresholdSec: number;
|
|
17
|
-
/**
|
|
17
|
+
/** Repeat notification cooldown (seconds) */
|
|
18
18
|
alertCooldownSec: number;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export const DEFAULT_MONITOR_CONFIG: MonitorConfig = {
|
|
22
22
|
approvalAlert: true,
|
|
23
23
|
longGeneratingAlert: true,
|
|
24
|
-
longGeneratingThresholdSec: 180, //
|
|
25
|
-
alertCooldownSec: 60, //
|
|
24
|
+
longGeneratingThresholdSec: 180, // 3 minutes
|
|
25
|
+
alertCooldownSec: 60, // 1 minute cooldown
|
|
26
26
|
};
|
|
27
27
|
|
|
28
28
|
export interface MonitorEvent {
|
|
@@ -42,24 +42,24 @@ export class StatusMonitor {
|
|
|
42
42
|
this.config = { ...DEFAULT_MONITOR_CONFIG, ...config };
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
/**
|
|
45
|
+
/** Update config (called from Provider Settings) */
|
|
46
46
|
updateConfig(partial: Partial<MonitorConfig>): void {
|
|
47
47
|
Object.assign(this.config, partial);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/** current config
|
|
50
|
+
/** Return current config */
|
|
51
51
|
getConfig(): MonitorConfig {
|
|
52
52
|
return { ...this.config };
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
* Check status transition → return notification event array.
|
|
57
|
+
* Called from each onTick() or detectStatusTransition().
|
|
58
|
+
*/
|
|
59
59
|
check(agentKey: string, status: string, now: number): MonitorEvent[] {
|
|
60
60
|
const events: MonitorEvent[] = [];
|
|
61
61
|
|
|
62
|
-
// 1.
|
|
62
|
+
// 1. Approval waiting notification
|
|
63
63
|
if (this.config.approvalAlert && status === 'waiting_approval') {
|
|
64
64
|
if (this.shouldAlert(agentKey + ':approval', now)) {
|
|
65
65
|
events.push({
|
|
@@ -71,7 +71,7 @@ export class StatusMonitor {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
// 2. Detect prolonged generating (identical for IDE/Extension/CLI)
|
|
74
|
+
// 2. Detect prolonged generating (identical for IDE/Extension/CLI/ACP)
|
|
75
75
|
if (status === 'generating' || status === 'streaming') {
|
|
76
76
|
if (!this.generatingStartTimes.has(agentKey)) {
|
|
77
77
|
this.generatingStartTimes.set(agentKey, now);
|