adhdev 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.js CHANGED
@@ -5847,6 +5847,25 @@ var init_setup = __esm({
5847
5847
  }
5848
5848
  });
5849
5849
 
5850
+ // ../../oss/packages/daemon-core/src/runtime-defaults.ts
5851
+ var 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;
5852
+ var init_runtime_defaults = __esm({
5853
+ "../../oss/packages/daemon-core/src/runtime-defaults.ts"() {
5854
+ "use strict";
5855
+ DEFAULT_CDP_SCAN_INTERVAL_MS = 3e4;
5856
+ DEFAULT_CDP_DISCOVERY_INTERVAL_MS = 3e4;
5857
+ DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS = 2e3;
5858
+ DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS = 3e4;
5859
+ DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS = 5e3;
5860
+ MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS = 5e3;
5861
+ DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS = 15e3;
5862
+ MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS = 5e3;
5863
+ DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS = 1e4;
5864
+ DEFAULT_SESSION_HOST_READY_TIMEOUT_MS = 15e3;
5865
+ STANDALONE_CDP_SCAN_INTERVAL_MS = 15e3;
5866
+ }
5867
+ });
5868
+
5850
5869
  // ../../oss/packages/daemon-core/src/cdp/scanner.ts
5851
5870
  var DaemonCdpScanner;
5852
5871
  var init_scanner = __esm({
@@ -5855,6 +5874,7 @@ var init_scanner = __esm({
5855
5874
  init_manager();
5856
5875
  init_setup();
5857
5876
  init_logger();
5877
+ init_runtime_defaults();
5858
5878
  DaemonCdpScanner = class {
5859
5879
  ctx;
5860
5880
  opts;
@@ -5888,7 +5908,7 @@ var init_scanner = __esm({
5888
5908
  */
5889
5909
  startPeriodicScan() {
5890
5910
  if (this.scanTimer) return;
5891
- const interval = this.opts.scanIntervalMs || 3e4;
5911
+ const interval = this.opts.scanIntervalMs || DEFAULT_CDP_SCAN_INTERVAL_MS;
5892
5912
  this.scanTimer = setInterval(async () => {
5893
5913
  const portMap = this.ctx.providerLoader.getCdpPortMap();
5894
5914
  for (const [ide, ports] of Object.entries(portMap)) {
@@ -5908,7 +5928,7 @@ var init_scanner = __esm({
5908
5928
  /**
5909
5929
  * Start periodic agent webview discovery on all connected CDPs.
5910
5930
  */
5911
- startWebviewDiscovery(intervalMs = 3e4) {
5931
+ startWebviewDiscovery(intervalMs = DEFAULT_CDP_DISCOVERY_INTERVAL_MS) {
5912
5932
  if (this.discoveryTimer) return;
5913
5933
  this.discoveryTimer = setInterval(async () => {
5914
5934
  for (const m of this.ctx.cdpManagers.values()) {
@@ -6008,6 +6028,7 @@ var init_initializer = __esm({
6008
6028
  init_setup();
6009
6029
  init_setup();
6010
6030
  init_logger();
6031
+ init_runtime_defaults();
6011
6032
  DaemonCdpInitializer = class {
6012
6033
  config;
6013
6034
  scanTimer = null;
@@ -6139,7 +6160,7 @@ var init_initializer = __esm({
6139
6160
  * Start periodic scanning for newly opened IDEs.
6140
6161
  * Idempotent — ignored if already started.
6141
6162
  */
6142
- startPeriodicScan(intervalMs = 3e4) {
6163
+ startPeriodicScan(intervalMs = DEFAULT_CDP_SCAN_INTERVAL_MS) {
6143
6164
  if (this.scanTimer) return;
6144
6165
  this.scanTimer = setInterval(async () => {
6145
6166
  const { providerLoader, cdpManagers } = this.config;
@@ -6153,7 +6174,7 @@ var init_initializer = __esm({
6153
6174
  /**
6154
6175
  * Start periodic agent webview discovery.
6155
6176
  */
6156
- startDiscovery(intervalMs = 3e4) {
6177
+ startDiscovery(intervalMs = DEFAULT_CDP_DISCOVERY_INTERVAL_MS) {
6157
6178
  if (this.discoveryTimer) return;
6158
6179
  this.discoveryTimer = setInterval(async () => {
6159
6180
  for (const m of this.config.cdpManagers.values()) {
@@ -12450,8 +12471,25 @@ var init_provider_cli_adapter = __esm({
12450
12471
  index: typeof message.index === "number" ? message.index : index,
12451
12472
  receivedAt: typeof message.receivedAt === "number" ? message.receivedAt : message.timestamp
12452
12473
  }));
12453
- const shouldPreferCommittedHistoryReplay = !this.currentTurnScope && !this.activeModal && committedHydratedMessages.length > parsedHydratedMessages.length;
12454
- const hydratedMessages = shouldPreferCommittedMessages || shouldPreferCommittedHistoryReplay ? committedHydratedMessages : parsedHydratedMessages;
12474
+ const parsedLastAssistant = [...parsedHydratedMessages].reverse().find((message) => message.role === "assistant" && typeof message.content === "string" && message.content.trim());
12475
+ const shouldAdoptParsedIdleReplay = !this.currentTurnScope && !this.activeModal && this.currentStatus === "idle" && parsedHydratedMessages.length > committedHydratedMessages.length && !!parsedLastAssistant;
12476
+ if (shouldAdoptParsedIdleReplay) {
12477
+ this.committedMessages = normalizeCliParsedMessages(parsed.messages, {
12478
+ committedMessages: this.committedMessages,
12479
+ scope: this.currentTurnScope,
12480
+ lastOutputAt: this.lastOutputAt
12481
+ });
12482
+ this.syncMessageViews();
12483
+ }
12484
+ const effectiveCommittedHydratedMessages = shouldAdoptParsedIdleReplay ? this.committedMessages.map((message, index) => buildChatMessage({
12485
+ ...message,
12486
+ id: message.id || `msg_${index}`,
12487
+ index: typeof message.index === "number" ? message.index : index,
12488
+ receivedAt: typeof message.receivedAt === "number" ? message.receivedAt : message.timestamp
12489
+ })) : committedHydratedMessages;
12490
+ const shouldPreferCommittedHistoryReplay = !this.currentTurnScope && !this.activeModal && effectiveCommittedHydratedMessages.length > parsedHydratedMessages.length;
12491
+ const shouldPreferCommittedIdleReplay = shouldPreferCommittedMessages && !shouldAdoptParsedIdleReplay;
12492
+ const hydratedMessages = shouldPreferCommittedIdleReplay || shouldPreferCommittedHistoryReplay ? effectiveCommittedHydratedMessages : parsedHydratedMessages;
12455
12493
  result = {
12456
12494
  id: parsed.id || "cli_session",
12457
12495
  status: parsed.status || this.currentStatus,
@@ -37193,6 +37231,7 @@ var init_reporter = __esm({
37193
37231
  "../../oss/packages/daemon-core/src/status/reporter.ts"() {
37194
37232
  "use strict";
37195
37233
  init_logger();
37234
+ init_runtime_defaults();
37196
37235
  init_builders();
37197
37236
  init_snapshot();
37198
37237
  DaemonStatusReporter = class {
@@ -37213,19 +37252,19 @@ var init_reporter = __esm({
37213
37252
  startReporting() {
37214
37253
  setTimeout(() => {
37215
37254
  this.sendUnifiedStatusReport({ forceServer: true, reason: "initial" }).catch((e) => LOG.warn("Status", `Initial report failed: ${e?.message}`));
37216
- }, 2e3);
37255
+ }, DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS);
37217
37256
  const scheduleServerReport = () => {
37218
37257
  this.statusTimer = setTimeout(() => {
37219
37258
  this.sendUnifiedStatusReport({ forceServer: true, reason: "periodic" }).catch((e) => LOG.warn("Status", `Periodic report failed: ${e?.message}`));
37220
37259
  scheduleServerReport();
37221
- }, 3e4);
37260
+ }, DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS);
37222
37261
  };
37223
37262
  scheduleServerReport();
37224
37263
  this.p2pTimer = setInterval(() => {
37225
37264
  if (this.deps.p2p?.isConnected) {
37226
37265
  this.sendUnifiedStatusReport({ p2pOnly: true }).catch((e) => LOG.warn("Status", `P2P status send failed: ${e?.message}`));
37227
37266
  }
37228
- }, 5e3);
37267
+ }, DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS);
37229
37268
  }
37230
37269
  stopReporting() {
37231
37270
  if (this.statusTimer) {
@@ -37243,14 +37282,14 @@ var init_reporter = __esm({
37243
37282
  throttledReport() {
37244
37283
  const now = Date.now();
37245
37284
  const elapsed = now - this.lastStatusSentAt;
37246
- if (elapsed >= 5e3) {
37285
+ if (elapsed >= DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS) {
37247
37286
  this.sendUnifiedStatusReport().catch((e) => LOG.warn("Status", `Throttled report failed: ${e?.message}`));
37248
37287
  } else if (!this.statusPendingThrottle) {
37249
37288
  this.statusPendingThrottle = true;
37250
37289
  setTimeout(() => {
37251
37290
  this.statusPendingThrottle = false;
37252
37291
  this.sendUnifiedStatusReport().catch((e) => LOG.warn("Status", `Deferred report failed: ${e?.message}`));
37253
- }, 5e3 - elapsed);
37292
+ }, DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS - elapsed);
37254
37293
  }
37255
37294
  }
37256
37295
  toDaemonStatusEventName(value) {
@@ -44676,7 +44715,8 @@ var init_runtime_support = __esm({
44676
44715
  "../../oss/packages/daemon-core/src/session-host/runtime-support.ts"() {
44677
44716
  "use strict";
44678
44717
  init_dist();
44679
- STARTUP_TIMEOUT_MS = 8e3;
44718
+ init_runtime_defaults();
44719
+ STARTUP_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
44680
44720
  STARTUP_POLL_MS = 200;
44681
44721
  }
44682
44722
  });
@@ -45056,8 +45096,8 @@ async function initDaemonComponents(config2) {
45056
45096
  }
45057
45097
  });
45058
45098
  await cdpInitializer.connectAll(detectedIdesRef.value);
45059
- cdpInitializer.startPeriodicScan(config2.cdpScanIntervalMs ?? 3e4);
45060
- cdpInitializer.startDiscovery(3e4);
45099
+ cdpInitializer.startPeriodicScan(config2.cdpScanIntervalMs ?? DEFAULT_CDP_SCAN_INTERVAL_MS);
45100
+ cdpInitializer.startDiscovery(DEFAULT_CDP_DISCOVERY_INTERVAL_MS);
45061
45101
  const commandHandler = new DaemonCommandHandler({
45062
45102
  cdpManagers,
45063
45103
  ideType: "unknown",
@@ -45196,6 +45236,7 @@ var init_daemon_lifecycle = __esm({
45196
45236
  init_cli_detector();
45197
45237
  init_registry();
45198
45238
  init_logger();
45239
+ init_runtime_defaults();
45199
45240
  init_config();
45200
45241
  }
45201
45242
  });
@@ -45210,10 +45251,19 @@ __export(src_exports, {
45210
45251
  CliProviderInstance: () => CliProviderInstance,
45211
45252
  DAEMON_WS_PATH: () => DAEMON_WS_PATH,
45212
45253
  DEFAULT_ACTIVE_CHAT_POLL_STATUSES: () => DEFAULT_ACTIVE_CHAT_POLL_STATUSES,
45254
+ DEFAULT_CDP_DISCOVERY_INTERVAL_MS: () => DEFAULT_CDP_DISCOVERY_INTERVAL_MS,
45255
+ DEFAULT_CDP_SCAN_INTERVAL_MS: () => DEFAULT_CDP_SCAN_INTERVAL_MS,
45213
45256
  DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS: () => DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS,
45214
45257
  DEFAULT_DAEMON_PORT: () => DEFAULT_DAEMON_PORT,
45258
+ DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS: () => DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS,
45215
45259
  DEFAULT_SESSION_HOST_APP_NAME: () => DEFAULT_SESSION_HOST_APP_NAME,
45260
+ DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS: () => DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS,
45261
+ DEFAULT_SESSION_HOST_READY_TIMEOUT_MS: () => DEFAULT_SESSION_HOST_READY_TIMEOUT_MS,
45216
45262
  DEFAULT_STANDALONE_SESSION_HOST_APP_NAME: () => DEFAULT_STANDALONE_SESSION_HOST_APP_NAME,
45263
+ DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS: () => DEFAULT_STATUS_INITIAL_REPORT_DELAY_MS,
45264
+ DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS: () => DEFAULT_STATUS_P2P_REPORT_INTERVAL_MS,
45265
+ DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS: () => DEFAULT_STATUS_SERVER_REPORT_INTERVAL_MS,
45266
+ DEV_SERVER_PORT: () => DEV_SERVER_PORT,
45217
45267
  DaemonAgentStreamManager: () => DaemonAgentStreamManager,
45218
45268
  DaemonCdpInitializer: () => DaemonCdpInitializer,
45219
45269
  DaemonCdpManager: () => DaemonCdpManager,
@@ -45225,10 +45275,13 @@ __export(src_exports, {
45225
45275
  DevServer: () => DevServer,
45226
45276
  IdeProviderInstance: () => IdeProviderInstance,
45227
45277
  LOG: () => LOG,
45278
+ MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS: () => MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS,
45279
+ MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS: () => MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS,
45228
45280
  NodePtyTransportFactory: () => NodePtyTransportFactory,
45229
45281
  ProviderCliAdapter: () => ProviderCliAdapter,
45230
45282
  ProviderInstanceManager: () => ProviderInstanceManager,
45231
45283
  ProviderLoader: () => ProviderLoader,
45284
+ STANDALONE_CDP_SCAN_INTERVAL_MS: () => STANDALONE_CDP_SCAN_INTERVAL_MS,
45232
45285
  SessionHostPtyTransportFactory: () => SessionHostPtyTransportFactory,
45233
45286
  VersionArchive: () => VersionArchive,
45234
45287
  appendRecentActivity: () => appendRecentActivity,
@@ -45367,6 +45420,7 @@ var init_src = __esm({
45367
45420
  init_cli_manager();
45368
45421
  init_launch();
45369
45422
  init_ipc_protocol();
45423
+ init_runtime_defaults();
45370
45424
  init_chat_history();
45371
45425
  init_chat_signatures();
45372
45426
  init_subscription_updates();
@@ -45626,6 +45680,10 @@ var init_server_connection = __esm({
45626
45680
  }
45627
45681
  }
45628
45682
  scheduleReconnect() {
45683
+ if (this.reconnectTimer) {
45684
+ clearTimeout(this.reconnectTimer);
45685
+ this.reconnectTimer = null;
45686
+ }
45629
45687
  const delay = Math.min(2e3 * Math.pow(1.5, this.reconnectAttempts), 6e4);
45630
45688
  this.reconnectAttempts++;
45631
45689
  LOG.info("Server", `[ServerConn] Reconnecting in ${(delay / 1e3).toFixed(1)}s (attempt ${this.reconnectAttempts})...`);
@@ -46273,9 +46331,44 @@ async function initiateConnection(deps, peerId, sharePermission) {
46273
46331
  clearTimeout(peer.failedCleanupTimer);
46274
46332
  peer.failedCleanupTimer = void 0;
46275
46333
  }
46334
+ if (peer.disconnectTimer) {
46335
+ clearTimeout(peer.disconnectTimer);
46336
+ peer.disconnectTimer = void 0;
46337
+ }
46276
46338
  deps.notifyStateChange();
46339
+ } else if (pcState === "disconnected") {
46340
+ log(`Peer ${pid} ICE disconnected \u2014 waiting 3s for recovery`);
46341
+ if (peer.disconnectTimer) clearTimeout(peer.disconnectTimer);
46342
+ peer.disconnectTimer = setTimeout(() => {
46343
+ const p = deps.peers.get(pid);
46344
+ if (!p) return;
46345
+ p.disconnectTimer = void 0;
46346
+ let currentState;
46347
+ try {
46348
+ currentState = pc.state?.();
46349
+ } catch {
46350
+ }
46351
+ if (currentState !== "connected") {
46352
+ log(`Peer ${pid} ICE recovery timeout (state=${currentState ?? "unknown"}) \u2014 marking failed`);
46353
+ p.state = "failed";
46354
+ deps.notifyStateChange();
46355
+ if (!p.failedCleanupTimer) {
46356
+ p.failedCleanupTimer = setTimeout(() => {
46357
+ const pp = deps.peers.get(pid);
46358
+ if (pp?.state === "failed") {
46359
+ log(`Auto-cleanup stale failed peer ${pid}`);
46360
+ disconnectPeer(deps.peers, pid, deps.notifyStateChange);
46361
+ }
46362
+ }, 3e4);
46363
+ }
46364
+ }
46365
+ }, 3e3);
46277
46366
  } else if (pcState === "failed" || pcState === "closed") {
46278
46367
  peer.state = "failed";
46368
+ if (peer.disconnectTimer) {
46369
+ clearTimeout(peer.disconnectTimer);
46370
+ peer.disconnectTimer = void 0;
46371
+ }
46279
46372
  deps.notifyStateChange();
46280
46373
  if (!peer.failedCleanupTimer) {
46281
46374
  peer.failedCleanupTimer = setTimeout(() => {
@@ -46433,6 +46526,7 @@ function disconnectPeer(peers, peerId, notifyStateChange) {
46433
46526
  if (peer.failedCleanupTimer) clearTimeout(peer.failedCleanupTimer);
46434
46527
  if (peer.heartbeatTimer) clearInterval(peer.heartbeatTimer);
46435
46528
  if (peer.connectionTimeout) clearTimeout(peer.connectionTimeout);
46529
+ if (peer.disconnectTimer) clearTimeout(peer.disconnectTimer);
46436
46530
  if (peer.dataChannel) try {
46437
46531
  peer.dataChannel.close();
46438
46532
  } catch {
@@ -53834,8 +53928,9 @@ var init_session_host = __esm({
53834
53928
  init_src();
53835
53929
  init_dist();
53836
53930
  init_session_host_hygiene();
53931
+ init_runtime_defaults();
53837
53932
  SESSION_HOST_APP_NAME = process.env.ADHDEV_SESSION_HOST_NAME || DEFAULT_SESSION_HOST_APP_NAME;
53838
- SESSION_HOST_START_TIMEOUT_MS = 15e3;
53933
+ SESSION_HOST_START_TIMEOUT_MS = DEFAULT_SESSION_HOST_READY_TIMEOUT_MS;
53839
53934
  }
53840
53935
  });
53841
53936
 
@@ -54677,7 +54772,8 @@ var init_adhdev_daemon = __esm({
54677
54772
  init_source2();
54678
54773
  init_version();
54679
54774
  init_src();
54680
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.87" });
54775
+ init_runtime_defaults();
54776
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.88" });
54681
54777
  AdhdevDaemon = class _AdhdevDaemon {
54682
54778
  localHttpServer = null;
54683
54779
  localWss = null;
@@ -54709,7 +54805,7 @@ var init_adhdev_daemon = __esm({
54709
54805
  "session_host_restart_session"
54710
54806
  ]);
54711
54807
  constructor() {
54712
- this.localPort = 19222;
54808
+ this.localPort = DEFAULT_DAEMON_PORT;
54713
54809
  }
54714
54810
  applyDebugRuntime(options) {
54715
54811
  this.debugConfig = resolveDebugRuntimeConfig({
@@ -54900,7 +54996,10 @@ var init_adhdev_daemon = __esm({
54900
54996
  }
54901
54997
  }
54902
54998
  buildMachineRuntimeUpdateForSubscription(subscription) {
54903
- const intervalMs = Math.max(5e3, Number(subscription.params.intervalMs || 15e3));
54999
+ const intervalMs = Math.max(
55000
+ MIN_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS,
55001
+ Number(subscription.params.intervalMs || DEFAULT_MACHINE_RUNTIME_SUBSCRIPTION_INTERVAL_MS)
55002
+ );
54904
55003
  const now = Date.now();
54905
55004
  if (subscription.lastSentAt > 0 && now - subscription.lastSentAt < intervalMs) {
54906
55005
  return null;
@@ -54921,7 +55020,10 @@ var init_adhdev_daemon = __esm({
54921
55020
  }
54922
55021
  async buildSessionHostDiagnosticsUpdateForSubscription(subscription) {
54923
55022
  if (!this.sessionHostController) return null;
54924
- const intervalMs = Math.max(5e3, Number(subscription.params.intervalMs || 1e4));
55023
+ const intervalMs = Math.max(
55024
+ MIN_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS,
55025
+ Number(subscription.params.intervalMs || DEFAULT_SESSION_HOST_DIAGNOSTICS_SUBSCRIPTION_INTERVAL_MS)
55026
+ );
54925
55027
  const now = Date.now();
54926
55028
  if (subscription.lastSentAt > 0 && now - subscription.lastSentAt < intervalMs) {
54927
55029
  return null;
@@ -87044,7 +87146,7 @@ async function startDaemonFlow() {
87044
87146
  });
87045
87147
  }
87046
87148
  } catch {
87047
- daemon.start({ localPort: 19222, foreground: false }).catch(() => {
87149
+ daemon.start({ localPort: DEFAULT_DAEMON_PORT, foreground: false }).catch(() => {
87048
87150
  });
87049
87151
  }
87050
87152
  let started = false;