@adhdev/daemon-core 0.8.87 → 0.8.88
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 +2 -1
- package/dist/index.js +70 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -14
- package/dist/index.mjs.map +1 -1
- package/dist/runtime-defaults.d.ts +11 -0
- package/node_modules/@adhdev/session-host-core/package.json +1 -1
- package/package.json +1 -1
- package/src/boot/daemon-lifecycle.ts +7 -3
- package/src/cdp/initializer.ts +3 -2
- package/src/cdp/scanner.ts +3 -2
- package/src/cli-adapters/provider-cli-adapter.ts +31 -3
- package/src/index.ts +14 -1
- package/src/runtime-defaults.ts +16 -0
- package/src/session-host/runtime-support.ts +2 -1
- package/src/status/reporter.ts +10 -5
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const DEFAULT_CDP_SCAN_INTERVAL_MS = 30000;
|
|
2
|
+
export declare const DEFAULT_CDP_DISCOVERY_INTERVAL_MS = 30000;
|
|
3
|
+
export declare const DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS = 2000;
|
|
4
|
+
export declare const DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS = 30000;
|
|
5
|
+
export declare const DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS = 5000;
|
|
6
|
+
export declare const MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS = 5000;
|
|
7
|
+
export declare const DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS = 15000;
|
|
8
|
+
export declare const MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS = 5000;
|
|
9
|
+
export declare const DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS = 10000;
|
|
10
|
+
export declare const DEFAULT_SESSION_HOST_READY_TIMEOUT_MS = 15000;
|
|
11
|
+
export declare const STANDALONE_CDP_SCAN_INTERVAL_MS = 15000;
|
package/package.json
CHANGED
|
@@ -27,7 +27,11 @@ import { DevServer } from '../daemon/dev-server.js';
|
|
|
27
27
|
import { detectIDEs, type IDEInfo } from '../detection/ide-detector.js';
|
|
28
28
|
import { detectCLI, detectCLIs } from '../detection/cli-detector.js';
|
|
29
29
|
import { SessionRegistry } from '../sessions/registry.js';
|
|
30
|
-
import {
|
|
30
|
+
import { LOG, installGlobalInterceptor } from '../logging/logger.js';
|
|
31
|
+
import {
|
|
32
|
+
DEFAULT_CDP_DISCOVERY_INTERVAL_MS,
|
|
33
|
+
DEFAULT_CDP_SCAN_INTERVAL_MS,
|
|
34
|
+
} from '../runtime-defaults.js';
|
|
31
35
|
import { loadConfig } from '../config/config.js';
|
|
32
36
|
import type { PtyTransportFactory } from '../cli-adapters/pty-transport.js';
|
|
33
37
|
import type { IdeProviderInstance } from '../providers/ide-provider-instance.js';
|
|
@@ -240,8 +244,8 @@ export async function initDaemonComponents(config: DaemonInitConfig): Promise<Da
|
|
|
240
244
|
},
|
|
241
245
|
});
|
|
242
246
|
await cdpInitializer.connectAll(detectedIdesRef.value);
|
|
243
|
-
cdpInitializer.startPeriodicScan(config.cdpScanIntervalMs ??
|
|
244
|
-
cdpInitializer.startDiscovery(
|
|
247
|
+
cdpInitializer.startPeriodicScan(config.cdpScanIntervalMs ?? DEFAULT_CDP_SCAN_INTERVAL_MS);
|
|
248
|
+
cdpInitializer.startDiscovery(DEFAULT_CDP_DISCOVERY_INTERVAL_MS);
|
|
245
249
|
|
|
246
250
|
// 7. CommandHandler
|
|
247
251
|
const commandHandler = new DaemonCommandHandler({
|
package/src/cdp/initializer.ts
CHANGED
|
@@ -14,6 +14,7 @@ import { registerExtensionProviders } from './setup.js';
|
|
|
14
14
|
import { probeCdpPort } from './setup.js';
|
|
15
15
|
import type { ProviderLoader } from '../providers/provider-loader.js';
|
|
16
16
|
import { LOG } from '../logging/logger.js';
|
|
17
|
+
import { DEFAULT_CDP_DISCOVERY_INTERVAL_MS, DEFAULT_CDP_SCAN_INTERVAL_MS } from '../runtime-defaults.js';
|
|
17
18
|
|
|
18
19
|
// ─── Config ───
|
|
19
20
|
|
|
@@ -206,7 +207,7 @@ export class DaemonCdpInitializer {
|
|
|
206
207
|
* Start periodic scanning for newly opened IDEs.
|
|
207
208
|
* Idempotent — ignored if already started.
|
|
208
209
|
*/
|
|
209
|
-
startPeriodicScan(intervalMs =
|
|
210
|
+
startPeriodicScan(intervalMs = DEFAULT_CDP_SCAN_INTERVAL_MS): void {
|
|
210
211
|
if (this.scanTimer) return;
|
|
211
212
|
|
|
212
213
|
this.scanTimer = setInterval(async () => {
|
|
@@ -224,7 +225,7 @@ export class DaemonCdpInitializer {
|
|
|
224
225
|
/**
|
|
225
226
|
* Start periodic agent webview discovery.
|
|
226
227
|
*/
|
|
227
|
-
startDiscovery(intervalMs =
|
|
228
|
+
startDiscovery(intervalMs = DEFAULT_CDP_DISCOVERY_INTERVAL_MS): void {
|
|
228
229
|
if (this.discoveryTimer) return;
|
|
229
230
|
|
|
230
231
|
this.discoveryTimer = setInterval(async () => {
|
package/src/cdp/scanner.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { DaemonCdpManager } from './manager.js';
|
|
|
12
12
|
import { ProviderLoader } from '../providers/provider-loader.js';
|
|
13
13
|
import { connectCdpManager, probeCdpPort, registerExtensionProviders, setupIdeInstance, type CdpSetupContext } from './setup.js';
|
|
14
14
|
import { LOG } from '../logging/logger.js';
|
|
15
|
+
import { DEFAULT_CDP_DISCOVERY_INTERVAL_MS, DEFAULT_CDP_SCAN_INTERVAL_MS } from '../runtime-defaults.js';
|
|
15
16
|
|
|
16
17
|
export interface CdpScannerOptions {
|
|
17
18
|
/** Context for setup operations */
|
|
@@ -68,7 +69,7 @@ export class DaemonCdpScanner {
|
|
|
68
69
|
*/
|
|
69
70
|
startPeriodicScan(): void {
|
|
70
71
|
if (this.scanTimer) return;
|
|
71
|
-
const interval = this.opts.scanIntervalMs ||
|
|
72
|
+
const interval = this.opts.scanIntervalMs || DEFAULT_CDP_SCAN_INTERVAL_MS;
|
|
72
73
|
|
|
73
74
|
this.scanTimer = setInterval(async () => {
|
|
74
75
|
const portMap = this.ctx.providerLoader.getCdpPortMap();
|
|
@@ -92,7 +93,7 @@ export class DaemonCdpScanner {
|
|
|
92
93
|
/**
|
|
93
94
|
* Start periodic agent webview discovery on all connected CDPs.
|
|
94
95
|
*/
|
|
95
|
-
startWebviewDiscovery(intervalMs =
|
|
96
|
+
startWebviewDiscovery(intervalMs = DEFAULT_CDP_DISCOVERY_INTERVAL_MS): void {
|
|
96
97
|
if (this.discoveryTimer) return;
|
|
97
98
|
this.discoveryTimer = setInterval(async () => {
|
|
98
99
|
for (const m of this.ctx.cdpManagers.values()) {
|
|
@@ -1550,12 +1550,40 @@ export class ProviderCliAdapter implements CliAdapter {
|
|
|
1550
1550
|
? message.receivedAt
|
|
1551
1551
|
: message.timestamp,
|
|
1552
1552
|
}));
|
|
1553
|
+
const parsedLastAssistant = [...parsedHydratedMessages].reverse().find((message) => message.role === 'assistant' && typeof message.content === 'string' && message.content.trim());
|
|
1554
|
+
const shouldAdoptParsedIdleReplay =
|
|
1555
|
+
!this.currentTurnScope
|
|
1556
|
+
&& !this.activeModal
|
|
1557
|
+
&& this.currentStatus === 'idle'
|
|
1558
|
+
&& parsedHydratedMessages.length > committedHydratedMessages.length
|
|
1559
|
+
&& !!parsedLastAssistant;
|
|
1560
|
+
if (shouldAdoptParsedIdleReplay) {
|
|
1561
|
+
this.committedMessages = normalizeCliParsedMessages(parsed.messages, {
|
|
1562
|
+
committedMessages: this.committedMessages,
|
|
1563
|
+
scope: this.currentTurnScope,
|
|
1564
|
+
lastOutputAt: this.lastOutputAt,
|
|
1565
|
+
});
|
|
1566
|
+
this.syncMessageViews();
|
|
1567
|
+
}
|
|
1568
|
+
const effectiveCommittedHydratedMessages = shouldAdoptParsedIdleReplay
|
|
1569
|
+
? this.committedMessages.map((message, index) => buildChatMessage({
|
|
1570
|
+
...message,
|
|
1571
|
+
id: message.id || `msg_${index}`,
|
|
1572
|
+
index: typeof message.index === 'number' ? message.index : index,
|
|
1573
|
+
receivedAt: typeof message.receivedAt === 'number'
|
|
1574
|
+
? message.receivedAt
|
|
1575
|
+
: message.timestamp,
|
|
1576
|
+
}))
|
|
1577
|
+
: committedHydratedMessages;
|
|
1553
1578
|
const shouldPreferCommittedHistoryReplay =
|
|
1554
1579
|
!this.currentTurnScope
|
|
1555
1580
|
&& !this.activeModal
|
|
1556
|
-
&&
|
|
1557
|
-
const
|
|
1558
|
-
|
|
1581
|
+
&& effectiveCommittedHydratedMessages.length > parsedHydratedMessages.length;
|
|
1582
|
+
const shouldPreferCommittedIdleReplay =
|
|
1583
|
+
shouldPreferCommittedMessages
|
|
1584
|
+
&& !shouldAdoptParsedIdleReplay;
|
|
1585
|
+
const hydratedMessages = (shouldPreferCommittedIdleReplay || shouldPreferCommittedHistoryReplay)
|
|
1586
|
+
? effectiveCommittedHydratedMessages
|
|
1559
1587
|
: parsedHydratedMessages;
|
|
1560
1588
|
result = {
|
|
1561
1589
|
id: parsed.id || 'cli_session',
|
package/src/index.ts
CHANGED
|
@@ -185,6 +185,19 @@ export { launchWithCdp, getAvailableIdeIds, killIdeProcess, isIdeRunning } from
|
|
|
185
185
|
|
|
186
186
|
// ── IPC ──
|
|
187
187
|
export { DEFAULT_DAEMON_PORT, DAEMON_WS_PATH } from './ipc-protocol.js';
|
|
188
|
+
export {
|
|
189
|
+
DEFAULT_CDP_SCAN_INTERVAL_MS,
|
|
190
|
+
DEFAULT_CDP_DISCOVERY_INTERVAL_MS,
|
|
191
|
+
DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS,
|
|
192
|
+
DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS,
|
|
193
|
+
DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS,
|
|
194
|
+
MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS,
|
|
195
|
+
DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS,
|
|
196
|
+
MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS,
|
|
197
|
+
DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS,
|
|
198
|
+
DEFAULT_SESSION_HOST_READY_TIMEOUT_MS,
|
|
199
|
+
STANDALONE_CDP_SCAN_INTERVAL_MS,
|
|
200
|
+
} from './runtime-defaults.js';
|
|
188
201
|
|
|
189
202
|
// ── Chat History ──
|
|
190
203
|
export { readChatHistory } from './config/chat-history.js';
|
|
@@ -253,7 +266,7 @@ export { VersionArchive, detectAllVersions } from './providers/version-archive.j
|
|
|
253
266
|
export type { ProviderVersionInfo, VersionHistory } from './providers/version-archive.js';
|
|
254
267
|
|
|
255
268
|
// ── Dev Server ──
|
|
256
|
-
export { DevServer } from './daemon/dev-server.js';
|
|
269
|
+
export { DevServer, DEV_SERVER_PORT } from './daemon/dev-server.js';
|
|
257
270
|
|
|
258
271
|
// ── CLI Adapters ──
|
|
259
272
|
export { ProviderCliAdapter } from './cli-adapters/provider-cli-adapter.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const DEFAULT_CDP_SCAN_INTERVAL_MS = 30_000;
|
|
2
|
+
export const DEFAULT_CDP_DISCOVERY_INTERVAL_MS = 30_000;
|
|
3
|
+
|
|
4
|
+
export const DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS = 2_000;
|
|
5
|
+
export const DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS = 30_000;
|
|
6
|
+
export const DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS = 5_000;
|
|
7
|
+
|
|
8
|
+
export const MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS = 5_000;
|
|
9
|
+
export const DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS = 15_000;
|
|
10
|
+
|
|
11
|
+
export const MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS = 5_000;
|
|
12
|
+
export const DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS = 10_000;
|
|
13
|
+
|
|
14
|
+
export const DEFAULT_SESSION_HOST_READY_TIMEOUT_MS = 15_000;
|
|
15
|
+
|
|
16
|
+
export const STANDALONE_CDP_SCAN_INTERVAL_MS = 15_000;
|
|
@@ -5,8 +5,9 @@ import {
|
|
|
5
5
|
type SessionHostRecord,
|
|
6
6
|
} from '@adhdev/session-host-core';
|
|
7
7
|
import type { HostedCliRuntimeDescriptor } from '../commands/cli-manager.js';
|
|
8
|
+
import { DEFAULT_SESSION_HOST_READY_TIMEOUT_MS } from '../runtime-defaults.js';
|
|
8
9
|
|
|
9
|
-
const STARTUP_TIMEOUT_MS =
|
|
10
|
+
const STARTUP_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
|
|
10
11
|
const STARTUP_POLL_MS = 200;
|
|
11
12
|
|
|
12
13
|
async function canConnect(endpoint: SessionHostEndpoint): Promise<boolean> {
|
package/src/status/reporter.ts
CHANGED
|
@@ -6,6 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { LOG } from '../logging/logger.js';
|
|
9
|
+
import {
|
|
10
|
+
DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS,
|
|
11
|
+
DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS,
|
|
12
|
+
DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS,
|
|
13
|
+
} from '../runtime-defaults.js';
|
|
9
14
|
import type { DaemonCdpManager } from '../cdp/manager.js';
|
|
10
15
|
import type { MachineInfo } from '../shared-types.js';
|
|
11
16
|
import type { CloudStatusReportPayload, DaemonStatusEventPayload } from '../shared-types.js';
|
|
@@ -63,13 +68,13 @@ export class DaemonStatusReporter {
|
|
|
63
68
|
startReporting(): void {
|
|
64
69
|
setTimeout(() => {
|
|
65
70
|
this.sendUnifiedStatusReport({ forceServer: true, reason: 'initial' }).catch(e => LOG.warn('Status', `Initial report failed: ${e?.message}`));
|
|
66
|
-
},
|
|
71
|
+
}, DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS);
|
|
67
72
|
|
|
68
73
|
const scheduleServerReport = () => {
|
|
69
74
|
this.statusTimer = setTimeout(() => {
|
|
70
75
|
this.sendUnifiedStatusReport({ forceServer: true, reason: 'periodic' }).catch(e => LOG.warn('Status', `Periodic report failed: ${e?.message}`));
|
|
71
76
|
scheduleServerReport();
|
|
72
|
-
},
|
|
77
|
+
}, DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS);
|
|
73
78
|
};
|
|
74
79
|
scheduleServerReport();
|
|
75
80
|
|
|
@@ -77,7 +82,7 @@ export class DaemonStatusReporter {
|
|
|
77
82
|
if (this.deps.p2p?.isConnected) {
|
|
78
83
|
this.sendUnifiedStatusReport({ p2pOnly: true }).catch(e => LOG.warn('Status', `P2P status send failed: ${e?.message}`));
|
|
79
84
|
}
|
|
80
|
-
},
|
|
85
|
+
}, DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS);
|
|
81
86
|
}
|
|
82
87
|
|
|
83
88
|
stopReporting(): void {
|
|
@@ -92,14 +97,14 @@ export class DaemonStatusReporter {
|
|
|
92
97
|
throttledReport(): void {
|
|
93
98
|
const now = Date.now();
|
|
94
99
|
const elapsed = now - this.lastStatusSentAt;
|
|
95
|
-
if (elapsed >=
|
|
100
|
+
if (elapsed >= DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS) {
|
|
96
101
|
this.sendUnifiedStatusReport().catch(e => LOG.warn('Status', `Throttled report failed: ${e?.message}`));
|
|
97
102
|
} else if (!this.statusPendingThrottle) {
|
|
98
103
|
this.statusPendingThrottle = true;
|
|
99
104
|
setTimeout(() => {
|
|
100
105
|
this.statusPendingThrottle = false;
|
|
101
106
|
this.sendUnifiedStatusReport().catch(e => LOG.warn('Status', `Deferred report failed: ${e?.message}`));
|
|
102
|
-
},
|
|
107
|
+
}, DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS - elapsed);
|
|
103
108
|
}
|
|
104
109
|
}
|
|
105
110
|
|