adhdev 0.9.23 → 0.9.25

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
@@ -10030,6 +10030,7 @@ var init_handler = __esm({
10030
10030
  init_stream_commands();
10031
10031
  init_workspace_commands();
10032
10032
  COMMAND_DEBUG_LEVELS = /* @__PURE__ */ new Set([
10033
+ "read_chat",
10033
10034
  "pty_input",
10034
10035
  "pty_resize",
10035
10036
  "cdp_eval",
@@ -14578,8 +14579,10 @@ var init_provider_cli_adapter = __esm({
14578
14579
  if (buttonIndex in this.approvalKeys) {
14579
14580
  this.ptyProcess.write(this.approvalKeys[buttonIndex]);
14580
14581
  } else {
14582
+ const buttonCount = Array.isArray(modal?.buttons) ? modal.buttons.length : 0;
14583
+ const clampedIndex = buttonCount > 0 ? Math.min(Math.max(0, buttonIndex), buttonCount - 1) : Math.max(0, buttonIndex);
14581
14584
  const DOWN = "\x1B[B";
14582
- const keys = DOWN.repeat(Math.max(0, buttonIndex)) + "\r";
14585
+ const keys = DOWN.repeat(clampedIndex) + "\r";
14583
14586
  this.ptyProcess.write(keys);
14584
14587
  }
14585
14588
  }
@@ -38485,6 +38488,9 @@ var init_router = __esm({
38485
38488
  if (logs.length > 0) {
38486
38489
  return { success: true, logs, totalBuffered: logs.length };
38487
38490
  }
38491
+ if (sinceTs > 0) {
38492
+ return { success: true, logs: [], totalBuffered: 0 };
38493
+ }
38488
38494
  if (fs9.existsSync(LOG_PATH)) {
38489
38495
  const content = fs9.readFileSync(LOG_PATH, "utf-8");
38490
38496
  const allLines = content.split("\n");
@@ -46370,8 +46376,8 @@ var init_session_host_transport = __esm({
46370
46376
  }
46371
46377
  try {
46372
46378
  await this.client.close();
46373
- } catch {
46374
- if (destroy) throw new Error(`Failed to close session host client: ${this.options.runtimeId}`);
46379
+ } catch (err) {
46380
+ if (destroy) throw err instanceof Error ? err : new Error(`Failed to close session host client: ${this.options.runtimeId}`);
46375
46381
  }
46376
46382
  }
46377
46383
  };
@@ -79185,7 +79191,7 @@ var init_screenshot_sender = __esm({
79185
79191
  });
79186
79192
  let sentAny = false;
79187
79193
  for (const peer of peers.values()) {
79188
- if (peer.state !== "connected" || !peer.dataChannel) continue;
79194
+ if (peer.state !== "connected" || !peer.dataChannel?.isOpen()) continue;
79189
79195
  try {
79190
79196
  peer.dataChannel.sendMessage(payload);
79191
79197
  sentAny = true;
@@ -79202,7 +79208,7 @@ var init_screenshot_sender = __esm({
79202
79208
  });
79203
79209
  let sentAny = false;
79204
79210
  for (const peer of peers.values()) {
79205
- if (peer.state !== "connected" || !peer.dataChannel) continue;
79211
+ if (peer.state !== "connected" || !peer.dataChannel?.isOpen()) continue;
79206
79212
  try {
79207
79213
  peer.dataChannel.sendMessage(payload);
79208
79214
  sentAny = true;
@@ -79212,7 +79218,7 @@ var init_screenshot_sender = __esm({
79212
79218
  return sentAny;
79213
79219
  }
79214
79220
  sendTopicUpdateToPeer(peer, update) {
79215
- if (!peer?.dataChannel || peer.state !== "connected") return false;
79221
+ if (!peer?.dataChannel || peer.state !== "connected" || !peer.dataChannel.isOpen()) return false;
79216
79222
  try {
79217
79223
  peer.dataChannel.sendMessage(JSON.stringify({
79218
79224
  type: "topic_update",
@@ -79228,7 +79234,7 @@ var init_screenshot_sender = __esm({
79228
79234
  const msg = JSON.stringify({ type: "session_output", sessionId, data });
79229
79235
  let sentAny = false;
79230
79236
  for (const peer of peers.values()) {
79231
- if (peer.state !== "connected" || !peer.dataChannel) continue;
79237
+ if (peer.state !== "connected" || !peer.dataChannel?.isOpen()) continue;
79232
79238
  try {
79233
79239
  peer.dataChannel.sendMessage(msg);
79234
79240
  sentAny = true;
@@ -79754,7 +79760,7 @@ ${e?.stack || ""}`);
79754
79760
  }
79755
79761
  get isConnected() {
79756
79762
  for (const peer of this.peers.values()) {
79757
- if (peer.state === "connected" && peer.dataChannel) return true;
79763
+ if (peer.state === "connected" && peer.dataChannel?.isOpen()) return true;
79758
79764
  }
79759
79765
  return false;
79760
79766
  }
@@ -79932,7 +79938,22 @@ ${e?.stack || ""}`);
79932
79938
  if (!update) return;
79933
79939
  this.screenshotSender.sendTopicUpdateToPeer(peer, update);
79934
79940
  } catch (error48) {
79935
- log(`chat_tail flush skipped: peer=${peer.peerId} session=${subscription.params.targetSessionId} error=${error48?.message || error48}`);
79941
+ log(`chat_tail flush error: peer=${peer.peerId} session=${subscription.params.targetSessionId} error=${error48?.message || error48}`);
79942
+ const errorUpdate = {
79943
+ topic: "session.chat_tail",
79944
+ key: subscription.key,
79945
+ sessionId: subscription.params.targetSessionId,
79946
+ seq: subscription.seq,
79947
+ timestamp: Date.now(),
79948
+ syncMode: "noop",
79949
+ messages: [],
79950
+ status: "",
79951
+ replaceFrom: 0,
79952
+ totalMessages: 0,
79953
+ lastMessageSignature: "",
79954
+ error: error48?.message || "chat_tail build failed"
79955
+ };
79956
+ this.screenshotSender.sendTopicUpdateToPeer(peer, errorUpdate);
79936
79957
  }
79937
79958
  }, { concurrency: 4 });
79938
79959
  }
@@ -87437,7 +87458,7 @@ var init_adhdev_daemon = __esm({
87437
87458
  init_version();
87438
87459
  init_src();
87439
87460
  init_runtime_defaults();
87440
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.23" });
87461
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.25" });
87441
87462
  AdhdevDaemon = class _AdhdevDaemon {
87442
87463
  localHttpServer = null;
87443
87464
  localWss = null;
@@ -87451,6 +87472,8 @@ var init_adhdev_daemon = __esm({
87451
87472
  pendingP2PChatFlush = false;
87452
87473
  pendingP2PChatFlushOnlyActive = true;
87453
87474
  hotP2PChatSessionIds = /* @__PURE__ */ new Set();
87475
+ hotChatSnapshotCache = null;
87476
+ static HOT_CHAT_SNAPSHOT_CACHE_TTL_MS = 1500;
87454
87477
  components = null;
87455
87478
  sessionHostEndpoint = null;
87456
87479
  sessionHostController = null;
@@ -87632,8 +87655,17 @@ var init_adhdev_daemon = __esm({
87632
87655
  profile: "live"
87633
87656
  });
87634
87657
  }
87658
+ invalidateHotChatSnapshotCache() {
87659
+ this.hotChatSnapshotCache = null;
87660
+ }
87635
87661
  getHotChatSessionIdsForP2PFlush() {
87636
- const sessions = this.buildLiveStatusSnapshot().sessions || [];
87662
+ const now = Date.now();
87663
+ const cached2 = this.hotChatSnapshotCache;
87664
+ const sessions = cached2 && now - cached2.builtAt < _AdhdevDaemon.HOT_CHAT_SNAPSHOT_CACHE_TTL_MS ? cached2.sessions : (() => {
87665
+ const built = this.buildLiveStatusSnapshot().sessions || [];
87666
+ this.hotChatSnapshotCache = { sessions: built, builtAt: now };
87667
+ return built;
87668
+ })();
87637
87669
  const hotSessions = classifyHotChatSessionsForSubscriptionFlush(
87638
87670
  sessions,
87639
87671
  this.hotP2PChatSessionIds
@@ -87865,6 +87897,7 @@ ${err?.stack || ""}`);
87865
87897
  }
87866
87898
  }),
87867
87899
  onStatusChange: () => {
87900
+ this.invalidateHotChatSnapshotCache();
87868
87901
  this.statusReporter?.onStatusChange();
87869
87902
  void this.flushP2PChatSubscriptions({ onlyActive: true });
87870
87903
  },
@@ -87894,6 +87927,7 @@ ${err?.stack || ""}`);
87894
87927
  statusInstanceId: instanceId,
87895
87928
  statusVersion: pkgVersion,
87896
87929
  onStatusChange: () => {
87930
+ this.invalidateHotChatSnapshotCache();
87897
87931
  this.statusReporter?.onStatusChange();
87898
87932
  void this.flushP2PChatSubscriptions({ onlyActive: true });
87899
87933
  },