@adhdev/daemon-core 0.8.86 → 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 CHANGED
@@ -60,6 +60,7 @@ export { logCommand, getRecentCommands } from './logging/command-log.js';
60
60
  export { DaemonCliManager } from './commands/cli-manager.js';
61
61
  export { launchWithCdp, getAvailableIdeIds, killIdeProcess, isIdeRunning } from './launch.js';
62
62
  export { DEFAULT_DAEMON_PORT, DAEMON_WS_PATH } from './ipc-protocol.js';
63
+ export { DEFAULT_CDP_SCAN_INTERVAL_MS, DEFAULT_CDP_DISCOVERY_INTERVAL_MS, DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS, DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS, DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS, MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS, DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS, MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS, DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS, DEFAULT_SESSION_HOST_READY_TIMEOUT_MS, STANDALONE_CDP_SCAN_INTERVAL_MS, } from './runtime-defaults.js';
63
64
  export { readChatHistory } from './config/chat-history.js';
64
65
  export { hashSignatureParts, buildChatMessageSignature, buildChatTailDeliverySignature, buildSessionModalDeliverySignature, } from './chat/chat-signatures.js';
65
66
  export type { ChatMessageSignatureInput, ChatTailDeliverySignatureInput, SessionModalDeliverySignatureInput, } from './chat/chat-signatures.js';
@@ -84,7 +85,7 @@ export { BUILTIN_CHAT_MESSAGE_KINDS, isBuiltinChatMessageKind, normalizeChatMess
84
85
  export type { BuiltinChatMessageKind, ChatMessageKind } from './providers/chat-message-normalization.js';
85
86
  export { VersionArchive, detectAllVersions } from './providers/version-archive.js';
86
87
  export type { ProviderVersionInfo, VersionHistory } from './providers/version-archive.js';
87
- export { DevServer } from './daemon/dev-server.js';
88
+ export { DevServer, DEV_SERVER_PORT } from './daemon/dev-server.js';
88
89
  export { ProviderCliAdapter } from './cli-adapters/provider-cli-adapter.js';
89
90
  export type { CliAdapter } from './cli-adapter-types.js';
90
91
  export { NodePtyTransportFactory } from './cli-adapters/pty-transport.js';
package/dist/index.js CHANGED
@@ -3136,8 +3136,25 @@ var init_provider_cli_adapter = __esm({
3136
3136
  index: typeof message.index === "number" ? message.index : index,
3137
3137
  receivedAt: typeof message.receivedAt === "number" ? message.receivedAt : message.timestamp
3138
3138
  }));
3139
- const shouldPreferCommittedHistoryReplay = !this.currentTurnScope && !this.activeModal && committedHydratedMessages.length > parsedHydratedMessages.length;
3140
- const hydratedMessages = shouldPreferCommittedMessages || shouldPreferCommittedHistoryReplay ? committedHydratedMessages : parsedHydratedMessages;
3139
+ const parsedLastAssistant = [...parsedHydratedMessages].reverse().find((message) => message.role === "assistant" && typeof message.content === "string" && message.content.trim());
3140
+ const shouldAdoptParsedIdleReplay = !this.currentTurnScope && !this.activeModal && this.currentStatus === "idle" && parsedHydratedMessages.length > committedHydratedMessages.length && !!parsedLastAssistant;
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
+ }
3149
+ const effectiveCommittedHydratedMessages = shouldAdoptParsedIdleReplay ? this.committedMessages.map((message, index) => buildChatMessage({
3150
+ ...message,
3151
+ id: message.id || `msg_${index}`,
3152
+ index: typeof message.index === "number" ? message.index : index,
3153
+ receivedAt: typeof message.receivedAt === "number" ? message.receivedAt : message.timestamp
3154
+ })) : committedHydratedMessages;
3155
+ const shouldPreferCommittedHistoryReplay = !this.currentTurnScope && !this.activeModal && effectiveCommittedHydratedMessages.length > parsedHydratedMessages.length;
3156
+ const shouldPreferCommittedIdleReplay = shouldPreferCommittedMessages && !shouldAdoptParsedIdleReplay;
3157
+ const hydratedMessages = shouldPreferCommittedIdleReplay || shouldPreferCommittedHistoryReplay ? effectiveCommittedHydratedMessages : parsedHydratedMessages;
3141
3158
  result = {
3142
3159
  id: parsed.id || "cli_session",
3143
3160
  status: parsed.status || this.currentStatus,
@@ -3855,10 +3872,19 @@ __export(index_exports, {
3855
3872
  CliProviderInstance: () => CliProviderInstance,
3856
3873
  DAEMON_WS_PATH: () => DAEMON_WS_PATH,
3857
3874
  DEFAULT_ACTIVE_CHAT_POLL_STATUSES: () => DEFAULT_ACTIVE_CHAT_POLL_STATUSES,
3875
+ DEFAULT_CDP_DISCOVERY_INTERVAL_MS: () => DEFAULT_CDP_DISCOVERY_INTERVAL_MS,
3876
+ DEFAULT_CDP_SCAN_INTERVAL_MS: () => DEFAULT_CDP_SCAN_INTERVAL_MS,
3858
3877
  DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS: () => DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS,
3859
3878
  DEFAULT_DAEMON_PORT: () => DEFAULT_DAEMON_PORT,
3879
+ DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS: () => DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS,
3860
3880
  DEFAULT_SESSION_HOST_APP_NAME: () => DEFAULT_SESSION_HOST_APP_NAME,
3881
+ DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS: () => DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS,
3882
+ DEFAULT_SESSION_HOST_READY_TIMEOUT_MS: () => DEFAULT_SESSION_HOST_READY_TIMEOUT_MS,
3861
3883
  DEFAULT_STANDALONE_SESSION_HOST_APP_NAME: () => DEFAULT_STANDALONE_SESSION_HOST_APP_NAME,
3884
+ DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS: () => DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS,
3885
+ DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS: () => DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS,
3886
+ DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS: () => DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS,
3887
+ DEV_SERVER_PORT: () => DEV_SERVER_PORT,
3862
3888
  DaemonAgentStreamManager: () => DaemonAgentStreamManager,
3863
3889
  DaemonCdpInitializer: () => DaemonCdpInitializer,
3864
3890
  DaemonCdpManager: () => DaemonCdpManager,
@@ -3870,10 +3896,13 @@ __export(index_exports, {
3870
3896
  DevServer: () => DevServer,
3871
3897
  IdeProviderInstance: () => IdeProviderInstance,
3872
3898
  LOG: () => LOG,
3899
+ MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS: () => MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS,
3900
+ MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS: () => MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS,
3873
3901
  NodePtyTransportFactory: () => NodePtyTransportFactory,
3874
3902
  ProviderCliAdapter: () => ProviderCliAdapter,
3875
3903
  ProviderInstanceManager: () => ProviderInstanceManager,
3876
3904
  ProviderLoader: () => ProviderLoader,
3905
+ STANDALONE_CDP_SCAN_INTERVAL_MS: () => STANDALONE_CDP_SCAN_INTERVAL_MS,
3877
3906
  SessionHostPtyTransportFactory: () => SessionHostPtyTransportFactory,
3878
3907
  VersionArchive: () => VersionArchive,
3879
3908
  appendRecentActivity: () => appendRecentActivity,
@@ -8734,6 +8763,21 @@ async function probeCdpPort(port, timeoutMs = 1e3) {
8734
8763
 
8735
8764
  // src/cdp/scanner.ts
8736
8765
  init_logger();
8766
+
8767
+ // src/runtime-defaults.ts
8768
+ var DEFAULT_CDP_SCAN_INTERVAL_MS = 3e4;
8769
+ var DEFAULT_CDP_DISCOVERY_INTERVAL_MS = 3e4;
8770
+ var DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS = 2e3;
8771
+ var DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS = 3e4;
8772
+ var DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS = 5e3;
8773
+ var MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS = 5e3;
8774
+ var DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS = 15e3;
8775
+ var MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS = 5e3;
8776
+ var DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS = 1e4;
8777
+ var DEFAULT_SESSION_HOST_READY_TIMEOUT_MS = 15e3;
8778
+ var STANDALONE_CDP_SCAN_INTERVAL_MS = 15e3;
8779
+
8780
+ // src/cdp/scanner.ts
8737
8781
  var DaemonCdpScanner = class {
8738
8782
  ctx;
8739
8783
  opts;
@@ -8767,7 +8811,7 @@ var DaemonCdpScanner = class {
8767
8811
  */
8768
8812
  startPeriodicScan() {
8769
8813
  if (this.scanTimer) return;
8770
- const interval = this.opts.scanIntervalMs || 3e4;
8814
+ const interval = this.opts.scanIntervalMs || DEFAULT_CDP_SCAN_INTERVAL_MS;
8771
8815
  this.scanTimer = setInterval(async () => {
8772
8816
  const portMap = this.ctx.providerLoader.getCdpPortMap();
8773
8817
  for (const [ide, ports] of Object.entries(portMap)) {
@@ -8787,7 +8831,7 @@ var DaemonCdpScanner = class {
8787
8831
  /**
8788
8832
  * Start periodic agent webview discovery on all connected CDPs.
8789
8833
  */
8790
- startWebviewDiscovery(intervalMs = 3e4) {
8834
+ startWebviewDiscovery(intervalMs = DEFAULT_CDP_DISCOVERY_INTERVAL_MS) {
8791
8835
  if (this.discoveryTimer) return;
8792
8836
  this.discoveryTimer = setInterval(async () => {
8793
8837
  for (const m of this.ctx.cdpManagers.values()) {
@@ -9009,7 +9053,7 @@ var DaemonCdpInitializer = class {
9009
9053
  * Start periodic scanning for newly opened IDEs.
9010
9054
  * Idempotent — ignored if already started.
9011
9055
  */
9012
- startPeriodicScan(intervalMs = 3e4) {
9056
+ startPeriodicScan(intervalMs = DEFAULT_CDP_SCAN_INTERVAL_MS) {
9013
9057
  if (this.scanTimer) return;
9014
9058
  this.scanTimer = setInterval(async () => {
9015
9059
  const { providerLoader, cdpManagers } = this.config;
@@ -9023,7 +9067,7 @@ var DaemonCdpInitializer = class {
9023
9067
  /**
9024
9068
  * Start periodic agent webview discovery.
9025
9069
  */
9026
- startDiscovery(intervalMs = 3e4) {
9070
+ startDiscovery(intervalMs = DEFAULT_CDP_DISCOVERY_INTERVAL_MS) {
9027
9071
  if (this.discoveryTimer) return;
9028
9072
  this.discoveryTimer = setInterval(async () => {
9029
9073
  for (const m of this.config.cdpManagers.values()) {
@@ -18223,19 +18267,19 @@ var DaemonStatusReporter = class {
18223
18267
  startReporting() {
18224
18268
  setTimeout(() => {
18225
18269
  this.sendUnifiedStatusReport({ forceServer: true, reason: "initial" }).catch((e) => LOG.warn("Status", `Initial report failed: ${e?.message}`));
18226
- }, 2e3);
18270
+ }, DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS);
18227
18271
  const scheduleServerReport = () => {
18228
18272
  this.statusTimer = setTimeout(() => {
18229
18273
  this.sendUnifiedStatusReport({ forceServer: true, reason: "periodic" }).catch((e) => LOG.warn("Status", `Periodic report failed: ${e?.message}`));
18230
18274
  scheduleServerReport();
18231
- }, 3e4);
18275
+ }, DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS);
18232
18276
  };
18233
18277
  scheduleServerReport();
18234
18278
  this.p2pTimer = setInterval(() => {
18235
18279
  if (this.deps.p2p?.isConnected) {
18236
18280
  this.sendUnifiedStatusReport({ p2pOnly: true }).catch((e) => LOG.warn("Status", `P2P status send failed: ${e?.message}`));
18237
18281
  }
18238
- }, 5e3);
18282
+ }, DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS);
18239
18283
  }
18240
18284
  stopReporting() {
18241
18285
  if (this.statusTimer) {
@@ -18253,14 +18297,14 @@ var DaemonStatusReporter = class {
18253
18297
  throttledReport() {
18254
18298
  const now = Date.now();
18255
18299
  const elapsed = now - this.lastStatusSentAt;
18256
- if (elapsed >= 5e3) {
18300
+ if (elapsed >= DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS) {
18257
18301
  this.sendUnifiedStatusReport().catch((e) => LOG.warn("Status", `Throttled report failed: ${e?.message}`));
18258
18302
  } else if (!this.statusPendingThrottle) {
18259
18303
  this.statusPendingThrottle = true;
18260
18304
  setTimeout(() => {
18261
18305
  this.statusPendingThrottle = false;
18262
18306
  this.sendUnifiedStatusReport().catch((e) => LOG.warn("Status", `Deferred report failed: ${e?.message}`));
18263
- }, 5e3 - elapsed);
18307
+ }, DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS - elapsed);
18264
18308
  }
18265
18309
  }
18266
18310
  toDaemonStatusEventName(value) {
@@ -25515,7 +25559,7 @@ function resolveSessionHostAppName(options = {}) {
25515
25559
 
25516
25560
  // src/session-host/runtime-support.ts
25517
25561
  var import_session_host_core3 = require("@adhdev/session-host-core");
25518
- var STARTUP_TIMEOUT_MS = 8e3;
25562
+ var STARTUP_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
25519
25563
  var STARTUP_POLL_MS = 200;
25520
25564
  async function canConnect(endpoint) {
25521
25565
  const client = new import_session_host_core3.SessionHostClient({ endpoint });
@@ -25931,8 +25975,8 @@ async function initDaemonComponents(config) {
25931
25975
  }
25932
25976
  });
25933
25977
  await cdpInitializer.connectAll(detectedIdesRef.value);
25934
- cdpInitializer.startPeriodicScan(config.cdpScanIntervalMs ?? 3e4);
25935
- cdpInitializer.startDiscovery(3e4);
25978
+ cdpInitializer.startPeriodicScan(config.cdpScanIntervalMs ?? DEFAULT_CDP_SCAN_INTERVAL_MS);
25979
+ cdpInitializer.startDiscovery(DEFAULT_CDP_DISCOVERY_INTERVAL_MS);
25936
25980
  const commandHandler = new DaemonCommandHandler({
25937
25981
  cdpManagers,
25938
25982
  ideType: "unknown",
@@ -26062,10 +26106,19 @@ async function shutdownDaemonComponents(components) {
26062
26106
  CliProviderInstance,
26063
26107
  DAEMON_WS_PATH,
26064
26108
  DEFAULT_ACTIVE_CHAT_POLL_STATUSES,
26109
+ DEFAULT_CDP_DISCOVERY_INTERVAL_MS,
26110
+ DEFAULT_CDP_SCAN_INTERVAL_MS,
26065
26111
  DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS,
26066
26112
  DEFAULT_DAEMON_PORT,
26113
+ DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS,
26067
26114
  DEFAULT_SESSION_HOST_APP_NAME,
26115
+ DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS,
26116
+ DEFAULT_SESSION_HOST_READY_TIMEOUT_MS,
26068
26117
  DEFAULT_STANDALONE_SESSION_HOST_APP_NAME,
26118
+ DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS,
26119
+ DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS,
26120
+ DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS,
26121
+ DEV_SERVER_PORT,
26069
26122
  DaemonAgentStreamManager,
26070
26123
  DaemonCdpInitializer,
26071
26124
  DaemonCdpManager,
@@ -26077,10 +26130,13 @@ async function shutdownDaemonComponents(components) {
26077
26130
  DevServer,
26078
26131
  IdeProviderInstance,
26079
26132
  LOG,
26133
+ MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS,
26134
+ MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS,
26080
26135
  NodePtyTransportFactory,
26081
26136
  ProviderCliAdapter,
26082
26137
  ProviderInstanceManager,
26083
26138
  ProviderLoader,
26139
+ STANDALONE_CDP_SCAN_INTERVAL_MS,
26084
26140
  SessionHostPtyTransportFactory,
26085
26141
  VersionArchive,
26086
26142
  appendRecentActivity,