@adhdev/daemon-core 0.8.87 → 0.8.89
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 +107 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -28
- 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 +78 -18
- 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
package/dist/index.mjs
CHANGED
|
@@ -2459,8 +2459,7 @@ var init_provider_cli_adapter = __esm({
|
|
|
2459
2459
|
const buttons = Array.isArray(modal.buttons) ? modal.buttons : [];
|
|
2460
2460
|
if (buttons.length !== 1) return false;
|
|
2461
2461
|
const buttonLabel = String(buttons[0] || "").trim();
|
|
2462
|
-
|
|
2463
|
-
return looksLikeConfirmOnlyLabel(buttonLabel) || /Quick safety check|project trust|trust (?:this project|the contents of this directory|the files in this folder)|Enter to confirm/i.test(modalText);
|
|
2462
|
+
return looksLikeConfirmOnlyLabel(buttonLabel);
|
|
2464
2463
|
}
|
|
2465
2464
|
async waitForInteractivePrompt(maxWaitMs = 5e3) {
|
|
2466
2465
|
const startedAt = Date.now();
|
|
@@ -3076,11 +3075,14 @@ var init_provider_cli_adapter = __esm({
|
|
|
3076
3075
|
}
|
|
3077
3076
|
// ─── Public API (CliAdapter) ───────────────────
|
|
3078
3077
|
getStatus() {
|
|
3078
|
+
const screenText = this.terminalScreen.getText() || "";
|
|
3079
|
+
const startupModal = this.startupParseGate ? this.getStartupConfirmationModal(screenText) : null;
|
|
3080
|
+
const effectiveStatus = this.parseErrorMessage ? "error" : startupModal ? "waiting_approval" : this.currentStatus;
|
|
3079
3081
|
return {
|
|
3080
|
-
status:
|
|
3082
|
+
status: effectiveStatus,
|
|
3081
3083
|
messages: [...this.committedMessages],
|
|
3082
3084
|
workingDir: this.workingDir,
|
|
3083
|
-
activeModal: this.activeModal,
|
|
3085
|
+
activeModal: startupModal || this.activeModal,
|
|
3084
3086
|
errorMessage: this.parseErrorMessage || void 0,
|
|
3085
3087
|
errorReason: this.parseErrorMessage ? "parse_error" : void 0
|
|
3086
3088
|
};
|
|
@@ -3133,8 +3135,38 @@ var init_provider_cli_adapter = __esm({
|
|
|
3133
3135
|
index: typeof message.index === "number" ? message.index : index,
|
|
3134
3136
|
receivedAt: typeof message.receivedAt === "number" ? message.receivedAt : message.timestamp
|
|
3135
3137
|
}));
|
|
3136
|
-
const
|
|
3137
|
-
const
|
|
3138
|
+
const parsedLastAssistant = [...parsedHydratedMessages].reverse().find((message) => message.role === "assistant" && typeof message.content === "string" && message.content.trim());
|
|
3139
|
+
const visibleIdlePrompt = this.looksLikeVisibleIdlePrompt(screenText);
|
|
3140
|
+
const shouldAdoptParsedIdleReplay = !this.currentTurnScope && !this.activeModal && !!parsedLastAssistant && parsedHydratedMessages.length > committedHydratedMessages.length && (this.currentStatus === "idle" || this.currentStatus === "generating" && this.isWaitingForResponse && parsed.status === "idle" && visibleIdlePrompt);
|
|
3141
|
+
if (shouldAdoptParsedIdleReplay) {
|
|
3142
|
+
this.committedMessages = normalizeCliParsedMessages(parsed.messages, {
|
|
3143
|
+
committedMessages: this.committedMessages,
|
|
3144
|
+
scope: this.currentTurnScope,
|
|
3145
|
+
lastOutputAt: this.lastOutputAt
|
|
3146
|
+
});
|
|
3147
|
+
this.syncMessageViews();
|
|
3148
|
+
if (this.currentStatus !== "idle" || this.isWaitingForResponse) {
|
|
3149
|
+
this.responseBuffer = "";
|
|
3150
|
+
this.isWaitingForResponse = false;
|
|
3151
|
+
this.responseSettleIgnoreUntil = 0;
|
|
3152
|
+
this.submitRetryUsed = false;
|
|
3153
|
+
this.submitRetryPromptSnippet = "";
|
|
3154
|
+
this.finishRetryCount = 0;
|
|
3155
|
+
this.currentTurnScope = null;
|
|
3156
|
+
this.activeModal = null;
|
|
3157
|
+
this.setStatus("idle", "parsed_idle_replay_commit");
|
|
3158
|
+
this.onStatusChange?.();
|
|
3159
|
+
}
|
|
3160
|
+
}
|
|
3161
|
+
const effectiveCommittedHydratedMessages = shouldAdoptParsedIdleReplay ? this.committedMessages.map((message, index) => buildChatMessage({
|
|
3162
|
+
...message,
|
|
3163
|
+
id: message.id || `msg_${index}`,
|
|
3164
|
+
index: typeof message.index === "number" ? message.index : index,
|
|
3165
|
+
receivedAt: typeof message.receivedAt === "number" ? message.receivedAt : message.timestamp
|
|
3166
|
+
})) : committedHydratedMessages;
|
|
3167
|
+
const shouldPreferCommittedHistoryReplay = !this.currentTurnScope && !this.activeModal && effectiveCommittedHydratedMessages.length > parsedHydratedMessages.length;
|
|
3168
|
+
const shouldPreferCommittedIdleReplay = shouldPreferCommittedMessages && !shouldAdoptParsedIdleReplay;
|
|
3169
|
+
const hydratedMessages = shouldPreferCommittedIdleReplay || shouldPreferCommittedHistoryReplay ? effectiveCommittedHydratedMessages : parsedHydratedMessages;
|
|
3138
3170
|
result = {
|
|
3139
3171
|
id: parsed.id || "cli_session",
|
|
3140
3172
|
status: parsed.status || this.currentStatus,
|
|
@@ -3735,8 +3767,9 @@ ${data.message || ""}`.trim();
|
|
|
3735
3767
|
this.ptyProcess?.write(data);
|
|
3736
3768
|
}
|
|
3737
3769
|
resolveModal(buttonIndex) {
|
|
3738
|
-
|
|
3739
|
-
const modal = this.activeModal;
|
|
3770
|
+
const screenText = this.terminalScreen.getText() || "";
|
|
3771
|
+
const modal = this.activeModal || this.getStartupConfirmationModal(screenText);
|
|
3772
|
+
if (!this.ptyProcess || this.currentStatus !== "waiting_approval" && !modal) return;
|
|
3740
3773
|
this.clearIdleFinishCandidate("resolve_modal");
|
|
3741
3774
|
this.recordTrace("resolve_modal", {
|
|
3742
3775
|
buttonIndex,
|
|
@@ -3751,7 +3784,10 @@ ${data.message || ""}`.trim();
|
|
|
3751
3784
|
}
|
|
3752
3785
|
this.setStatus("generating", "approval_resolved");
|
|
3753
3786
|
this.onStatusChange?.();
|
|
3754
|
-
|
|
3787
|
+
const startupTrustModal = /Quick safety check|project trust|trust (?:this project|the contents of this directory|the files in this folder)/i.test(String(modal?.message || ""));
|
|
3788
|
+
if (startupTrustModal && buttonIndex in this.approvalKeys) {
|
|
3789
|
+
this.ptyProcess.write(`${this.approvalKeys[buttonIndex]}\r`);
|
|
3790
|
+
} else if (this.shouldResolveModalWithEnter(modal, buttonIndex)) {
|
|
3755
3791
|
this.ptyProcess.write("\r");
|
|
3756
3792
|
} else if (buttonIndex in this.approvalKeys) {
|
|
3757
3793
|
this.ptyProcess.write(this.approvalKeys[buttonIndex]);
|
|
@@ -3772,20 +3808,24 @@ ${data.message || ""}`.trim();
|
|
|
3772
3808
|
}
|
|
3773
3809
|
}
|
|
3774
3810
|
getDebugState() {
|
|
3811
|
+
const screenText = sanitizeTerminalText(this.terminalScreen.getText());
|
|
3812
|
+
const startupModal = this.startupParseGate ? this.getStartupConfirmationModal(screenText) : null;
|
|
3813
|
+
const effectiveStatus = startupModal ? "waiting_approval" : this.currentStatus;
|
|
3814
|
+
const effectiveReady = this.ready || !!startupModal;
|
|
3775
3815
|
return {
|
|
3776
3816
|
type: this.cliType,
|
|
3777
3817
|
name: this.cliName,
|
|
3778
3818
|
providerResolution: this.providerResolutionMeta,
|
|
3779
|
-
status:
|
|
3780
|
-
ready:
|
|
3819
|
+
status: effectiveStatus,
|
|
3820
|
+
ready: effectiveReady,
|
|
3781
3821
|
startupParseGate: this.startupParseGate,
|
|
3782
3822
|
spawnAt: this.spawnAt,
|
|
3783
3823
|
workingDir: this.workingDir,
|
|
3784
|
-
messages: this.messages
|
|
3785
|
-
committedMessages: this.committedMessages
|
|
3786
|
-
structuredMessages: this.structuredMessages
|
|
3824
|
+
messages: this.messages,
|
|
3825
|
+
committedMessages: this.committedMessages,
|
|
3826
|
+
structuredMessages: this.structuredMessages,
|
|
3787
3827
|
messageCount: this.committedMessages.length,
|
|
3788
|
-
screenText:
|
|
3828
|
+
screenText: screenText.slice(-4e3),
|
|
3789
3829
|
currentTurnScope: this.currentTurnScope,
|
|
3790
3830
|
startupBuffer: this.startupBuffer.slice(-4e3),
|
|
3791
3831
|
recentOutputBuffer: this.recentOutputBuffer.slice(-500),
|
|
@@ -3800,7 +3840,7 @@ ${data.message || ""}`.trim();
|
|
|
3800
3840
|
lastScreenChangeAt: this.lastScreenChangeAt,
|
|
3801
3841
|
lastScreenSnapshot: this.lastScreenSnapshot.slice(-500),
|
|
3802
3842
|
isWaitingForResponse: this.isWaitingForResponse,
|
|
3803
|
-
activeModal: this.activeModal,
|
|
3843
|
+
activeModal: startupModal || this.activeModal,
|
|
3804
3844
|
lastApprovalResolvedAt: this.lastApprovalResolvedAt,
|
|
3805
3845
|
sendDelayMs: this.sendDelayMs,
|
|
3806
3846
|
sendKey: this.sendKey,
|
|
@@ -8595,6 +8635,21 @@ async function probeCdpPort(port, timeoutMs = 1e3) {
|
|
|
8595
8635
|
|
|
8596
8636
|
// src/cdp/scanner.ts
|
|
8597
8637
|
init_logger();
|
|
8638
|
+
|
|
8639
|
+
// src/runtime-defaults.ts
|
|
8640
|
+
var DEFAULT_CDP_SCAN_INTERVAL_MS = 3e4;
|
|
8641
|
+
var DEFAULT_CDP_DISCOVERY_INTERVAL_MS = 3e4;
|
|
8642
|
+
var DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS = 2e3;
|
|
8643
|
+
var DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS = 3e4;
|
|
8644
|
+
var DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS = 5e3;
|
|
8645
|
+
var MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS = 5e3;
|
|
8646
|
+
var DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS = 15e3;
|
|
8647
|
+
var MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS = 5e3;
|
|
8648
|
+
var DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS = 1e4;
|
|
8649
|
+
var DEFAULT_SESSION_HOST_READY_TIMEOUT_MS = 15e3;
|
|
8650
|
+
var STANDALONE_CDP_SCAN_INTERVAL_MS = 15e3;
|
|
8651
|
+
|
|
8652
|
+
// src/cdp/scanner.ts
|
|
8598
8653
|
var DaemonCdpScanner = class {
|
|
8599
8654
|
ctx;
|
|
8600
8655
|
opts;
|
|
@@ -8628,7 +8683,7 @@ var DaemonCdpScanner = class {
|
|
|
8628
8683
|
*/
|
|
8629
8684
|
startPeriodicScan() {
|
|
8630
8685
|
if (this.scanTimer) return;
|
|
8631
|
-
const interval = this.opts.scanIntervalMs ||
|
|
8686
|
+
const interval = this.opts.scanIntervalMs || DEFAULT_CDP_SCAN_INTERVAL_MS;
|
|
8632
8687
|
this.scanTimer = setInterval(async () => {
|
|
8633
8688
|
const portMap = this.ctx.providerLoader.getCdpPortMap();
|
|
8634
8689
|
for (const [ide, ports] of Object.entries(portMap)) {
|
|
@@ -8648,7 +8703,7 @@ var DaemonCdpScanner = class {
|
|
|
8648
8703
|
/**
|
|
8649
8704
|
* Start periodic agent webview discovery on all connected CDPs.
|
|
8650
8705
|
*/
|
|
8651
|
-
startWebviewDiscovery(intervalMs =
|
|
8706
|
+
startWebviewDiscovery(intervalMs = DEFAULT_CDP_DISCOVERY_INTERVAL_MS) {
|
|
8652
8707
|
if (this.discoveryTimer) return;
|
|
8653
8708
|
this.discoveryTimer = setInterval(async () => {
|
|
8654
8709
|
for (const m of this.ctx.cdpManagers.values()) {
|
|
@@ -8870,7 +8925,7 @@ var DaemonCdpInitializer = class {
|
|
|
8870
8925
|
* Start periodic scanning for newly opened IDEs.
|
|
8871
8926
|
* Idempotent — ignored if already started.
|
|
8872
8927
|
*/
|
|
8873
|
-
startPeriodicScan(intervalMs =
|
|
8928
|
+
startPeriodicScan(intervalMs = DEFAULT_CDP_SCAN_INTERVAL_MS) {
|
|
8874
8929
|
if (this.scanTimer) return;
|
|
8875
8930
|
this.scanTimer = setInterval(async () => {
|
|
8876
8931
|
const { providerLoader, cdpManagers } = this.config;
|
|
@@ -8884,7 +8939,7 @@ var DaemonCdpInitializer = class {
|
|
|
8884
8939
|
/**
|
|
8885
8940
|
* Start periodic agent webview discovery.
|
|
8886
8941
|
*/
|
|
8887
|
-
startDiscovery(intervalMs =
|
|
8942
|
+
startDiscovery(intervalMs = DEFAULT_CDP_DISCOVERY_INTERVAL_MS) {
|
|
8888
8943
|
if (this.discoveryTimer) return;
|
|
8889
8944
|
this.discoveryTimer = setInterval(async () => {
|
|
8890
8945
|
for (const m of this.config.cdpManagers.values()) {
|
|
@@ -18089,19 +18144,19 @@ var DaemonStatusReporter = class {
|
|
|
18089
18144
|
startReporting() {
|
|
18090
18145
|
setTimeout(() => {
|
|
18091
18146
|
this.sendUnifiedStatusReport({ forceServer: true, reason: "initial" }).catch((e) => LOG.warn("Status", `Initial report failed: ${e?.message}`));
|
|
18092
|
-
},
|
|
18147
|
+
}, DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS);
|
|
18093
18148
|
const scheduleServerReport = () => {
|
|
18094
18149
|
this.statusTimer = setTimeout(() => {
|
|
18095
18150
|
this.sendUnifiedStatusReport({ forceServer: true, reason: "periodic" }).catch((e) => LOG.warn("Status", `Periodic report failed: ${e?.message}`));
|
|
18096
18151
|
scheduleServerReport();
|
|
18097
|
-
},
|
|
18152
|
+
}, DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS);
|
|
18098
18153
|
};
|
|
18099
18154
|
scheduleServerReport();
|
|
18100
18155
|
this.p2pTimer = setInterval(() => {
|
|
18101
18156
|
if (this.deps.p2p?.isConnected) {
|
|
18102
18157
|
this.sendUnifiedStatusReport({ p2pOnly: true }).catch((e) => LOG.warn("Status", `P2P status send failed: ${e?.message}`));
|
|
18103
18158
|
}
|
|
18104
|
-
},
|
|
18159
|
+
}, DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS);
|
|
18105
18160
|
}
|
|
18106
18161
|
stopReporting() {
|
|
18107
18162
|
if (this.statusTimer) {
|
|
@@ -18119,14 +18174,14 @@ var DaemonStatusReporter = class {
|
|
|
18119
18174
|
throttledReport() {
|
|
18120
18175
|
const now = Date.now();
|
|
18121
18176
|
const elapsed = now - this.lastStatusSentAt;
|
|
18122
|
-
if (elapsed >=
|
|
18177
|
+
if (elapsed >= DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS) {
|
|
18123
18178
|
this.sendUnifiedStatusReport().catch((e) => LOG.warn("Status", `Throttled report failed: ${e?.message}`));
|
|
18124
18179
|
} else if (!this.statusPendingThrottle) {
|
|
18125
18180
|
this.statusPendingThrottle = true;
|
|
18126
18181
|
setTimeout(() => {
|
|
18127
18182
|
this.statusPendingThrottle = false;
|
|
18128
18183
|
this.sendUnifiedStatusReport().catch((e) => LOG.warn("Status", `Deferred report failed: ${e?.message}`));
|
|
18129
|
-
},
|
|
18184
|
+
}, DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS - elapsed);
|
|
18130
18185
|
}
|
|
18131
18186
|
}
|
|
18132
18187
|
toDaemonStatusEventName(value) {
|
|
@@ -25386,7 +25441,7 @@ import {
|
|
|
25386
25441
|
SessionHostClient as SessionHostClient2,
|
|
25387
25442
|
getDefaultSessionHostEndpoint
|
|
25388
25443
|
} from "@adhdev/session-host-core";
|
|
25389
|
-
var STARTUP_TIMEOUT_MS =
|
|
25444
|
+
var STARTUP_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
|
|
25390
25445
|
var STARTUP_POLL_MS = 200;
|
|
25391
25446
|
async function canConnect(endpoint) {
|
|
25392
25447
|
const client = new SessionHostClient2({ endpoint });
|
|
@@ -25802,8 +25857,8 @@ async function initDaemonComponents(config) {
|
|
|
25802
25857
|
}
|
|
25803
25858
|
});
|
|
25804
25859
|
await cdpInitializer.connectAll(detectedIdesRef.value);
|
|
25805
|
-
cdpInitializer.startPeriodicScan(config.cdpScanIntervalMs ??
|
|
25806
|
-
cdpInitializer.startDiscovery(
|
|
25860
|
+
cdpInitializer.startPeriodicScan(config.cdpScanIntervalMs ?? DEFAULT_CDP_SCAN_INTERVAL_MS);
|
|
25861
|
+
cdpInitializer.startDiscovery(DEFAULT_CDP_DISCOVERY_INTERVAL_MS);
|
|
25807
25862
|
const commandHandler = new DaemonCommandHandler({
|
|
25808
25863
|
cdpManagers,
|
|
25809
25864
|
ideType: "unknown",
|
|
@@ -25932,10 +25987,19 @@ export {
|
|
|
25932
25987
|
CliProviderInstance,
|
|
25933
25988
|
DAEMON_WS_PATH,
|
|
25934
25989
|
DEFAULT_ACTIVE_CHAT_POLL_STATUSES,
|
|
25990
|
+
DEFAULT_CDP_DISCOVERY_INTERVAL_MS,
|
|
25991
|
+
DEFAULT_CDP_SCAN_INTERVAL_MS,
|
|
25935
25992
|
DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS,
|
|
25936
25993
|
DEFAULT_DAEMON_PORT,
|
|
25994
|
+
DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS,
|
|
25937
25995
|
DEFAULT_SESSION_HOST_APP_NAME,
|
|
25996
|
+
DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS,
|
|
25997
|
+
DEFAULT_SESSION_HOST_READY_TIMEOUT_MS,
|
|
25938
25998
|
DEFAULT_STANDALONE_SESSION_HOST_APP_NAME,
|
|
25999
|
+
DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS,
|
|
26000
|
+
DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS,
|
|
26001
|
+
DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS,
|
|
26002
|
+
DEV_SERVER_PORT,
|
|
25939
26003
|
DaemonAgentStreamManager,
|
|
25940
26004
|
DaemonCdpInitializer,
|
|
25941
26005
|
DaemonCdpManager,
|
|
@@ -25947,10 +26011,13 @@ export {
|
|
|
25947
26011
|
DevServer,
|
|
25948
26012
|
IdeProviderInstance,
|
|
25949
26013
|
LOG,
|
|
26014
|
+
MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS,
|
|
26015
|
+
MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS,
|
|
25950
26016
|
NodePtyTransportFactory,
|
|
25951
26017
|
ProviderCliAdapter,
|
|
25952
26018
|
ProviderInstanceManager,
|
|
25953
26019
|
ProviderLoader,
|
|
26020
|
+
STANDALONE_CDP_SCAN_INTERVAL_MS,
|
|
25954
26021
|
SessionHostPtyTransportFactory,
|
|
25955
26022
|
VersionArchive,
|
|
25956
26023
|
appendRecentActivity,
|