adhdev 0.9.23 → 0.9.24

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/cli/index.js CHANGED
@@ -14578,8 +14578,10 @@ var init_provider_cli_adapter = __esm({
14578
14578
  if (buttonIndex in this.approvalKeys) {
14579
14579
  this.ptyProcess.write(this.approvalKeys[buttonIndex]);
14580
14580
  } else {
14581
+ const buttonCount = Array.isArray(modal?.buttons) ? modal.buttons.length : 0;
14582
+ const clampedIndex = buttonCount > 0 ? Math.min(Math.max(0, buttonIndex), buttonCount - 1) : Math.max(0, buttonIndex);
14581
14583
  const DOWN = "\x1B[B";
14582
- const keys = DOWN.repeat(Math.max(0, buttonIndex)) + "\r";
14584
+ const keys = DOWN.repeat(clampedIndex) + "\r";
14583
14585
  this.ptyProcess.write(keys);
14584
14586
  }
14585
14587
  }
@@ -46370,8 +46372,8 @@ var init_session_host_transport = __esm({
46370
46372
  }
46371
46373
  try {
46372
46374
  await this.client.close();
46373
- } catch {
46374
- if (destroy) throw new Error(`Failed to close session host client: ${this.options.runtimeId}`);
46375
+ } catch (err) {
46376
+ if (destroy) throw err instanceof Error ? err : new Error(`Failed to close session host client: ${this.options.runtimeId}`);
46375
46377
  }
46376
46378
  }
46377
46379
  };
@@ -79185,7 +79187,7 @@ var init_screenshot_sender = __esm({
79185
79187
  });
79186
79188
  let sentAny = false;
79187
79189
  for (const peer of peers.values()) {
79188
- if (peer.state !== "connected" || !peer.dataChannel) continue;
79190
+ if (peer.state !== "connected" || !peer.dataChannel?.isOpen()) continue;
79189
79191
  try {
79190
79192
  peer.dataChannel.sendMessage(payload);
79191
79193
  sentAny = true;
@@ -79202,7 +79204,7 @@ var init_screenshot_sender = __esm({
79202
79204
  });
79203
79205
  let sentAny = false;
79204
79206
  for (const peer of peers.values()) {
79205
- if (peer.state !== "connected" || !peer.dataChannel) continue;
79207
+ if (peer.state !== "connected" || !peer.dataChannel?.isOpen()) continue;
79206
79208
  try {
79207
79209
  peer.dataChannel.sendMessage(payload);
79208
79210
  sentAny = true;
@@ -79212,7 +79214,7 @@ var init_screenshot_sender = __esm({
79212
79214
  return sentAny;
79213
79215
  }
79214
79216
  sendTopicUpdateToPeer(peer, update) {
79215
- if (!peer?.dataChannel || peer.state !== "connected") return false;
79217
+ if (!peer?.dataChannel || peer.state !== "connected" || !peer.dataChannel.isOpen()) return false;
79216
79218
  try {
79217
79219
  peer.dataChannel.sendMessage(JSON.stringify({
79218
79220
  type: "topic_update",
@@ -79228,7 +79230,7 @@ var init_screenshot_sender = __esm({
79228
79230
  const msg = JSON.stringify({ type: "session_output", sessionId, data });
79229
79231
  let sentAny = false;
79230
79232
  for (const peer of peers.values()) {
79231
- if (peer.state !== "connected" || !peer.dataChannel) continue;
79233
+ if (peer.state !== "connected" || !peer.dataChannel?.isOpen()) continue;
79232
79234
  try {
79233
79235
  peer.dataChannel.sendMessage(msg);
79234
79236
  sentAny = true;
@@ -79754,7 +79756,7 @@ ${e?.stack || ""}`);
79754
79756
  }
79755
79757
  get isConnected() {
79756
79758
  for (const peer of this.peers.values()) {
79757
- if (peer.state === "connected" && peer.dataChannel) return true;
79759
+ if (peer.state === "connected" && peer.dataChannel?.isOpen()) return true;
79758
79760
  }
79759
79761
  return false;
79760
79762
  }
@@ -79932,7 +79934,22 @@ ${e?.stack || ""}`);
79932
79934
  if (!update) return;
79933
79935
  this.screenshotSender.sendTopicUpdateToPeer(peer, update);
79934
79936
  } catch (error48) {
79935
- log(`chat_tail flush skipped: peer=${peer.peerId} session=${subscription.params.targetSessionId} error=${error48?.message || error48}`);
79937
+ log(`chat_tail flush error: peer=${peer.peerId} session=${subscription.params.targetSessionId} error=${error48?.message || error48}`);
79938
+ const errorUpdate = {
79939
+ topic: "session.chat_tail",
79940
+ key: subscription.key,
79941
+ sessionId: subscription.params.targetSessionId,
79942
+ seq: subscription.seq,
79943
+ timestamp: Date.now(),
79944
+ syncMode: "noop",
79945
+ messages: [],
79946
+ status: "",
79947
+ replaceFrom: 0,
79948
+ totalMessages: 0,
79949
+ lastMessageSignature: "",
79950
+ error: error48?.message || "chat_tail build failed"
79951
+ };
79952
+ this.screenshotSender.sendTopicUpdateToPeer(peer, errorUpdate);
79936
79953
  }
79937
79954
  }, { concurrency: 4 });
79938
79955
  }
@@ -87437,7 +87454,7 @@ var init_adhdev_daemon = __esm({
87437
87454
  init_version();
87438
87455
  init_src();
87439
87456
  init_runtime_defaults();
87440
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.23" });
87457
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.24" });
87441
87458
  AdhdevDaemon = class _AdhdevDaemon {
87442
87459
  localHttpServer = null;
87443
87460
  localWss = null;
@@ -87451,6 +87468,8 @@ var init_adhdev_daemon = __esm({
87451
87468
  pendingP2PChatFlush = false;
87452
87469
  pendingP2PChatFlushOnlyActive = true;
87453
87470
  hotP2PChatSessionIds = /* @__PURE__ */ new Set();
87471
+ hotChatSnapshotCache = null;
87472
+ static HOT_CHAT_SNAPSHOT_CACHE_TTL_MS = 1500;
87454
87473
  components = null;
87455
87474
  sessionHostEndpoint = null;
87456
87475
  sessionHostController = null;
@@ -87632,8 +87651,17 @@ var init_adhdev_daemon = __esm({
87632
87651
  profile: "live"
87633
87652
  });
87634
87653
  }
87654
+ invalidateHotChatSnapshotCache() {
87655
+ this.hotChatSnapshotCache = null;
87656
+ }
87635
87657
  getHotChatSessionIdsForP2PFlush() {
87636
- const sessions = this.buildLiveStatusSnapshot().sessions || [];
87658
+ const now = Date.now();
87659
+ const cached2 = this.hotChatSnapshotCache;
87660
+ const sessions = cached2 && now - cached2.builtAt < _AdhdevDaemon.HOT_CHAT_SNAPSHOT_CACHE_TTL_MS ? cached2.sessions : (() => {
87661
+ const built = this.buildLiveStatusSnapshot().sessions || [];
87662
+ this.hotChatSnapshotCache = { sessions: built, builtAt: now };
87663
+ return built;
87664
+ })();
87637
87665
  const hotSessions = classifyHotChatSessionsForSubscriptionFlush(
87638
87666
  sessions,
87639
87667
  this.hotP2PChatSessionIds
@@ -87865,6 +87893,7 @@ ${err?.stack || ""}`);
87865
87893
  }
87866
87894
  }),
87867
87895
  onStatusChange: () => {
87896
+ this.invalidateHotChatSnapshotCache();
87868
87897
  this.statusReporter?.onStatusChange();
87869
87898
  void this.flushP2PChatSubscriptions({ onlyActive: true });
87870
87899
  },
@@ -87894,6 +87923,7 @@ ${err?.stack || ""}`);
87894
87923
  statusInstanceId: instanceId,
87895
87924
  statusVersion: pkgVersion,
87896
87925
  onStatusChange: () => {
87926
+ this.invalidateHotChatSnapshotCache();
87897
87927
  this.statusReporter?.onStatusChange();
87898
87928
  void this.flushP2PChatSubscriptions({ onlyActive: true });
87899
87929
  },