adhdev 0.9.9 → 0.9.11

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
@@ -7525,7 +7525,7 @@ function didProviderConfirmSend(result) {
7525
7525
  }
7526
7526
  async function readExtensionChatState(h) {
7527
7527
  try {
7528
- const evalResult = await h.evaluateProviderScript("readChat", void 0, 5e4);
7528
+ const evalResult = await h.evaluateProviderScript("readChat", void 0, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS);
7529
7529
  if (!evalResult?.result) return null;
7530
7530
  const parsed = parseMaybeJson(evalResult.result);
7531
7531
  return parsed && typeof parsed === "object" ? parsed : null;
@@ -7613,7 +7613,7 @@ async function handleReadChat(h, args) {
7613
7613
  const title = typeof parsedRecord?.title === "string" ? parsedRecord.title : void 0;
7614
7614
  const providerSessionId = typeof parsedRecord?.providerSessionId === "string" ? parsedRecord.providerSessionId : void 0;
7615
7615
  if (status) {
7616
- LOG.info("Command", `[read_chat] cli-like resolved provider=${adapter.cliType} target=${String(args?.targetSessionId || "")} adapterStatus=${String(adapterStatus.status || "")} parsedStatus=${String(parsedRecord?.status || "")} shouldPreferAdapterMessages=${String(shouldPreferAdapterMessages)} adapterMsgCount=${Array.isArray(adapterStatus.messages) ? adapterStatus.messages.length : 0} parsedMsgCount=${Array.isArray(parsedRecord?.messages) ? parsedRecord.messages.length : 0} returnedMsgCount=${Array.isArray(status.messages) ? status.messages.length : 0}`);
7616
+ LOG.debug("Command", `[read_chat] cli-like resolved provider=${adapter.cliType} target=${String(args?.targetSessionId || "")} adapterStatus=${String(adapterStatus.status || "")} parsedStatus=${String(parsedRecord?.status || "")} shouldPreferAdapterMessages=${String(shouldPreferAdapterMessages)} adapterMsgCount=${Array.isArray(adapterStatus.messages) ? adapterStatus.messages.length : 0} parsedMsgCount=${Array.isArray(parsedRecord?.messages) ? parsedRecord.messages.length : 0} returnedMsgCount=${Array.isArray(status.messages) ? status.messages.length : 0}`);
7617
7617
  return buildReadChatCommandResult({
7618
7618
  messages: status.messages || [],
7619
7619
  status: status.status,
@@ -7638,7 +7638,7 @@ async function handleReadChat(h, args) {
7638
7638
  }
7639
7639
  if (isExtensionTransport(transport)) {
7640
7640
  try {
7641
- const evalResult = await h.evaluateProviderScript("readChat", void 0, 5e4);
7641
+ const evalResult = await h.evaluateProviderScript("readChat", void 0, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS);
7642
7642
  if (evalResult?.result) {
7643
7643
  let parsed = evalResult.result;
7644
7644
  if (typeof parsed === "string") {
@@ -7742,7 +7742,7 @@ async function handleReadChat(h, args) {
7742
7742
  const script = h.getProviderScript("readChat") || h.getProviderScript("read_chat");
7743
7743
  if (script) {
7744
7744
  try {
7745
- const evalResult = await h.evaluateProviderScript("readChat", void 0, 5e4);
7745
+ const evalResult = await h.evaluateProviderScript("readChat", void 0, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS);
7746
7746
  if (evalResult?.result) {
7747
7747
  let parsed = evalResult.result;
7748
7748
  if (typeof parsed === "string") {
@@ -8446,7 +8446,7 @@ async function handleResolveAction(h, args) {
8446
8446
  }
8447
8447
  return { success: false, error: "resolveAction script not available for this provider" };
8448
8448
  }
8449
- var RECENT_SEND_WINDOW_MS, recentSendByTarget;
8449
+ var RECENT_SEND_WINDOW_MS, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS, recentSendByTarget;
8450
8450
  var init_chat_commands = __esm({
8451
8451
  "../../oss/packages/daemon-core/src/commands/chat-commands.ts"() {
8452
8452
  "use strict";
@@ -8459,6 +8459,7 @@ var init_chat_commands = __esm({
8459
8459
  init_chat_signatures();
8460
8460
  init_chat_message_normalization();
8461
8461
  RECENT_SEND_WINDOW_MS = 1200;
8462
+ READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS = 25e3;
8462
8463
  recentSendByTarget = /* @__PURE__ */ new Map();
8463
8464
  }
8464
8465
  });
@@ -11827,7 +11828,7 @@ var init_provider_cli_adapter = __esm({
11827
11828
  sendDelayMs;
11828
11829
  sendKey;
11829
11830
  submitStrategy;
11830
- static SCRIPT_STATUS_DEBOUNCE_MS = 1e3;
11831
+ static SCRIPT_STATUS_DEBOUNCE_MS = 3e3;
11831
11832
  /** Inject CLI scripts after construction (e.g. when resolved by ProviderLoader) */
11832
11833
  setCliScripts(scripts) {
11833
11834
  this.cliScripts = scripts;
@@ -13991,7 +13992,7 @@ var init_cli_provider_instance = __esm({
13991
13992
  this.generatingDebouncePending = null;
13992
13993
  }
13993
13994
  this.generatingDebounceTimer = null;
13994
- }, 1e3);
13995
+ }, 3e3);
13995
13996
  } else if (newStatus === "waiting_approval") {
13996
13997
  this.suppressIdleHistoryReplay = false;
13997
13998
  if (this.generatingDebouncePending) {
@@ -14047,7 +14048,7 @@ var init_cli_provider_instance = __esm({
14047
14048
  this.generatingStartedAt = 0;
14048
14049
  }
14049
14050
  this.completedDebounceTimer = null;
14050
- }, 2e3);
14051
+ }, 3e3);
14051
14052
  }
14052
14053
  } else if (newStatus === "stopped") {
14053
14054
  if (this.generatingDebounceTimer) {
@@ -46067,6 +46068,7 @@ var init_server_connection = __esm({
46067
46068
  reconnectTimer = null;
46068
46069
  pingTimer = null;
46069
46070
  pongTimeout = null;
46071
+ authTimeout = null;
46070
46072
  missedPongCount = 0;
46071
46073
  messageHandlers = /* @__PURE__ */ new Map();
46072
46074
  stateChangeCallbacks = [];
@@ -46076,6 +46078,9 @@ var init_server_connection = __esm({
46076
46078
  iceServers = null;
46077
46079
  planLimits = null;
46078
46080
  compatBlocked = false;
46081
+ get authTimeoutMs() {
46082
+ return Math.max(1, this.options.authTimeoutMs ?? 15e3);
46083
+ }
46079
46084
  constructor(options) {
46080
46085
  this.options = options;
46081
46086
  }
@@ -46178,6 +46183,7 @@ var init_server_connection = __esm({
46178
46183
  },
46179
46184
  timestamp: Date.now()
46180
46185
  });
46186
+ this.startAuthTimeout();
46181
46187
  }
46182
46188
  onMessage(text) {
46183
46189
  try {
@@ -46185,6 +46191,7 @@ var init_server_connection = __esm({
46185
46191
  this.missedPongCount = 0;
46186
46192
  const message = JSON.parse(text);
46187
46193
  if (message.type === "auth_ok") {
46194
+ this.clearAuthTimeout();
46188
46195
  this.reconnectAttempts = 0;
46189
46196
  this.compatBlocked = false;
46190
46197
  const payload = message.payload;
@@ -46199,6 +46206,7 @@ var init_server_connection = __esm({
46199
46206
  LOG.info("Server", `[ServerConn] \u2713 Authenticated (plan: ${this.userPlan})`);
46200
46207
  this.startHeartbeat();
46201
46208
  } else if (message.type === "auth_error") {
46209
+ this.clearAuthTimeout();
46202
46210
  LOG.error("Server", `Auth failed: ${message.payload.reason}`);
46203
46211
  this.setState("error");
46204
46212
  return;
@@ -46293,9 +46301,25 @@ var init_server_connection = __esm({
46293
46301
  clearTimeout(this.reconnectTimer);
46294
46302
  this.reconnectTimer = null;
46295
46303
  }
46304
+ this.clearAuthTimeout();
46296
46305
  this.stopHeartbeat();
46297
46306
  this.missedPongCount = 0;
46298
46307
  }
46308
+ startAuthTimeout() {
46309
+ this.clearAuthTimeout();
46310
+ this.authTimeout = setTimeout(() => {
46311
+ this.authTimeout = null;
46312
+ if (this.state !== "authenticating" || !this.ws) return;
46313
+ LOG.warn("Server", `[ServerConn] Auth timeout after ${(this.authTimeoutMs / 1e3).toFixed(1)}s \u2014 reconnecting`);
46314
+ this.ws.terminate();
46315
+ }, this.authTimeoutMs);
46316
+ }
46317
+ clearAuthTimeout() {
46318
+ if (this.authTimeout) {
46319
+ clearTimeout(this.authTimeout);
46320
+ this.authTimeout = null;
46321
+ }
46322
+ }
46299
46323
  // ─── WS Heartbeat (ping/pong) ─────────────────────
46300
46324
  startHeartbeat() {
46301
46325
  this.stopHeartbeat();
@@ -55372,7 +55396,7 @@ var init_adhdev_daemon = __esm({
55372
55396
  init_version();
55373
55397
  init_src();
55374
55398
  init_runtime_defaults();
55375
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.9" });
55399
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.11" });
55376
55400
  AdhdevDaemon = class _AdhdevDaemon {
55377
55401
  localHttpServer = null;
55378
55402
  localWss = null;
@@ -55396,6 +55420,7 @@ var init_adhdev_daemon = __esm({
55396
55420
  mandatoryUpgradeInFlight = false;
55397
55421
  debugConfig = resolveDebugRuntimeConfig();
55398
55422
  recentInteractionIdsBySession = /* @__PURE__ */ new Map();
55423
+ ptyInputDropLogLastAt = /* @__PURE__ */ new Map();
55399
55424
  static MANDATORY_UPDATE_BLOCKED_COMMANDS = /* @__PURE__ */ new Set([
55400
55425
  "launch_ide",
55401
55426
  "launch_cli",
@@ -55447,6 +55472,14 @@ var init_adhdev_daemon = __esm({
55447
55472
  const mode = this.getCliPresentationMode(sessionId);
55448
55473
  return mode === "chat" || mode === "terminal";
55449
55474
  }
55475
+ logPtyInputDrop(sessionId, reason) {
55476
+ const key = `${sessionId || "(missing)"}:${reason}`;
55477
+ const now = Date.now();
55478
+ const last = this.ptyInputDropLogLastAt.get(key) || 0;
55479
+ if (now - last < 3e4) return;
55480
+ this.ptyInputDropLogLastAt.set(key, now);
55481
+ LOG.warn("P2P", `PTY input dropped: session=${sessionId || "(missing)"} reason=${reason}`);
55482
+ }
55450
55483
  getUpgradePackageName() {
55451
55484
  return process.argv[1]?.includes("daemon-standalone") ? "@adhdev/daemon-standalone" : "adhdev";
55452
55485
  }
@@ -55559,9 +55592,13 @@ var init_adhdev_daemon = __esm({
55559
55592
  });
55560
55593
  }
55561
55594
  getHotChatSessionIdsForP2PFlush() {
55562
- const snapshot = this.buildLiveStatusSnapshot();
55595
+ const sessions = buildSessionEntries(
55596
+ this.components.instanceManager.collectAllStates(),
55597
+ this.components.cdpManagers,
55598
+ { profile: "live" }
55599
+ );
55563
55600
  const hotSessions = classifyHotChatSessionsForSubscriptionFlush(
55564
- snapshot.sessions,
55601
+ sessions,
55565
55602
  this.hotP2PChatSessionIds
55566
55603
  );
55567
55604
  this.hotP2PChatSessionIds = hotSessions.active;
@@ -55886,10 +55923,23 @@ ${err?.stack || ""}`);
55886
55923
  }
55887
55924
  });
55888
55925
  this.p2p.onPtyInput((sessionId, data) => {
55889
- if (!this.isCliSession(sessionId)) return;
55926
+ if (!this.isCliSession(sessionId)) {
55927
+ this.logPtyInputDrop(sessionId, "not_cli_session");
55928
+ return;
55929
+ }
55890
55930
  const found = this.components.cliManager.findAdapter(sessionId, { instanceKey: sessionId });
55891
- if (found && typeof found.adapter.writeRaw === "function") {
55931
+ if (!found) {
55932
+ this.logPtyInputDrop(sessionId, "adapter_not_found");
55933
+ return;
55934
+ }
55935
+ if (typeof found.adapter.writeRaw !== "function") {
55936
+ this.logPtyInputDrop(sessionId, "writeRaw_missing");
55937
+ return;
55938
+ }
55939
+ try {
55892
55940
  found.adapter.writeRaw(data);
55941
+ } catch {
55942
+ this.logPtyInputDrop(sessionId, "write_failed");
55893
55943
  }
55894
55944
  });
55895
55945
  this.p2p.onPtyResize((sessionId, cols, rows) => {