adhdev 0.9.8 → 0.9.10

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
@@ -5293,6 +5293,18 @@ function validateRole(role, source, index) {
5293
5293
  }
5294
5294
  return role;
5295
5295
  }
5296
+ function validateBubbleState(state, source, index) {
5297
+ if (typeof state !== "string" || !VALID_BUBBLE_STATES.includes(state)) {
5298
+ throw new Error(`${source}: messages[${index}].bubbleState must be one of ${VALID_BUBBLE_STATES.join(", ")}`);
5299
+ }
5300
+ return state;
5301
+ }
5302
+ function validateTurnStatus(turnStatus, source) {
5303
+ if (typeof turnStatus !== "string" || !VALID_TURN_STATUSES.includes(turnStatus)) {
5304
+ throw new Error(`${source}: turnStatus must be one of ${VALID_TURN_STATUSES.join(", ")}`);
5305
+ }
5306
+ return turnStatus;
5307
+ }
5296
5308
  function validateMessageContent(content, source, index) {
5297
5309
  if (typeof content === "string") return content;
5298
5310
  if (Array.isArray(content)) return normalizeMessageParts(content);
@@ -5308,6 +5320,9 @@ function validateMessage(message, source, index) {
5308
5320
  };
5309
5321
  if (typeof message.kind === "string") normalized.kind = message.kind;
5310
5322
  if (typeof message.id === "string") normalized.id = message.id;
5323
+ if (typeof message.bubbleId === "string") normalized.bubbleId = message.bubbleId;
5324
+ if (typeof message.providerUnitKey === "string") normalized.providerUnitKey = message.providerUnitKey;
5325
+ if (message.bubbleState !== void 0) normalized.bubbleState = validateBubbleState(message.bubbleState, source, index);
5311
5326
  if (isFiniteNumber(message.index)) normalized.index = message.index;
5312
5327
  if (isFiniteNumber(message.timestamp)) normalized.timestamp = message.timestamp;
5313
5328
  if (isFiniteNumber(message.receivedAt)) normalized.receivedAt = message.receivedAt;
@@ -5375,6 +5390,8 @@ function validateReadChatResultPayload(raw, source = "read_chat") {
5375
5390
  if (activeModal !== void 0) normalized.activeModal = activeModal;
5376
5391
  if (typeof raw.id === "string") normalized.id = raw.id;
5377
5392
  if (typeof raw.title === "string") normalized.title = raw.title;
5393
+ if (typeof raw.currentTurnId === "string") normalized.currentTurnId = raw.currentTurnId;
5394
+ if (raw.turnStatus !== void 0) normalized.turnStatus = validateTurnStatus(raw.turnStatus, source);
5378
5395
  if (typeof raw.agentType === "string") normalized.agentType = raw.agentType;
5379
5396
  if (typeof raw.agentName === "string") normalized.agentName = raw.agentName;
5380
5397
  if (typeof raw.extensionId === "string") normalized.extensionId = raw.extensionId;
@@ -5387,13 +5404,15 @@ function validateReadChatResultPayload(raw, source = "read_chat") {
5387
5404
  if (typeof raw.providerSessionId === "string") normalized.providerSessionId = raw.providerSessionId;
5388
5405
  return normalized;
5389
5406
  }
5390
- var VALID_STATUSES, VALID_ROLES;
5407
+ var VALID_STATUSES, VALID_ROLES, VALID_BUBBLE_STATES, VALID_TURN_STATUSES;
5391
5408
  var init_read_chat_contract = __esm({
5392
5409
  "../../oss/packages/daemon-core/src/providers/read-chat-contract.ts"() {
5393
5410
  "use strict";
5394
5411
  init_contracts();
5395
5412
  VALID_STATUSES = ["idle", "generating", "waiting_approval", "error", "panel_hidden", "streaming", "long_generating"];
5396
5413
  VALID_ROLES = ["user", "assistant", "system", "human"];
5414
+ VALID_BUBBLE_STATES = ["draft", "streaming", "final", "removed"];
5415
+ VALID_TURN_STATUSES = ["open", "waiting_approval", "complete", "error"];
5397
5416
  }
5398
5417
  });
5399
5418
 
@@ -7506,7 +7525,7 @@ function didProviderConfirmSend(result) {
7506
7525
  }
7507
7526
  async function readExtensionChatState(h) {
7508
7527
  try {
7509
- const evalResult = await h.evaluateProviderScript("readChat", void 0, 5e4);
7528
+ const evalResult = await h.evaluateProviderScript("readChat", void 0, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS);
7510
7529
  if (!evalResult?.result) return null;
7511
7530
  const parsed = parseMaybeJson(evalResult.result);
7512
7531
  return parsed && typeof parsed === "object" ? parsed : null;
@@ -7594,7 +7613,7 @@ async function handleReadChat(h, args) {
7594
7613
  const title = typeof parsedRecord?.title === "string" ? parsedRecord.title : void 0;
7595
7614
  const providerSessionId = typeof parsedRecord?.providerSessionId === "string" ? parsedRecord.providerSessionId : void 0;
7596
7615
  if (status) {
7597
- 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}`);
7598
7617
  return buildReadChatCommandResult({
7599
7618
  messages: status.messages || [],
7600
7619
  status: status.status,
@@ -7619,7 +7638,7 @@ async function handleReadChat(h, args) {
7619
7638
  }
7620
7639
  if (isExtensionTransport(transport)) {
7621
7640
  try {
7622
- const evalResult = await h.evaluateProviderScript("readChat", void 0, 5e4);
7641
+ const evalResult = await h.evaluateProviderScript("readChat", void 0, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS);
7623
7642
  if (evalResult?.result) {
7624
7643
  let parsed = evalResult.result;
7625
7644
  if (typeof parsed === "string") {
@@ -7723,7 +7742,7 @@ async function handleReadChat(h, args) {
7723
7742
  const script = h.getProviderScript("readChat") || h.getProviderScript("read_chat");
7724
7743
  if (script) {
7725
7744
  try {
7726
- const evalResult = await h.evaluateProviderScript("readChat", void 0, 5e4);
7745
+ const evalResult = await h.evaluateProviderScript("readChat", void 0, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS);
7727
7746
  if (evalResult?.result) {
7728
7747
  let parsed = evalResult.result;
7729
7748
  if (typeof parsed === "string") {
@@ -8427,7 +8446,7 @@ async function handleResolveAction(h, args) {
8427
8446
  }
8428
8447
  return { success: false, error: "resolveAction script not available for this provider" };
8429
8448
  }
8430
- var RECENT_SEND_WINDOW_MS, recentSendByTarget;
8449
+ var RECENT_SEND_WINDOW_MS, READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS, recentSendByTarget;
8431
8450
  var init_chat_commands = __esm({
8432
8451
  "../../oss/packages/daemon-core/src/commands/chat-commands.ts"() {
8433
8452
  "use strict";
@@ -8440,6 +8459,7 @@ var init_chat_commands = __esm({
8440
8459
  init_chat_signatures();
8441
8460
  init_chat_message_normalization();
8442
8461
  RECENT_SEND_WINDOW_MS = 1200;
8462
+ READ_CHAT_PROVIDER_EVAL_TIMEOUT_MS = 25e3;
8443
8463
  recentSendByTarget = /* @__PURE__ */ new Map();
8444
8464
  }
8445
8465
  });
@@ -11808,7 +11828,7 @@ var init_provider_cli_adapter = __esm({
11808
11828
  sendDelayMs;
11809
11829
  sendKey;
11810
11830
  submitStrategy;
11811
- static SCRIPT_STATUS_DEBOUNCE_MS = 1e3;
11831
+ static SCRIPT_STATUS_DEBOUNCE_MS = 3e3;
11812
11832
  /** Inject CLI scripts after construction (e.g. when resolved by ProviderLoader) */
11813
11833
  setCliScripts(scripts) {
11814
11834
  this.cliScripts = scripts;
@@ -13972,7 +13992,7 @@ var init_cli_provider_instance = __esm({
13972
13992
  this.generatingDebouncePending = null;
13973
13993
  }
13974
13994
  this.generatingDebounceTimer = null;
13975
- }, 1e3);
13995
+ }, 3e3);
13976
13996
  } else if (newStatus === "waiting_approval") {
13977
13997
  this.suppressIdleHistoryReplay = false;
13978
13998
  if (this.generatingDebouncePending) {
@@ -14028,7 +14048,7 @@ var init_cli_provider_instance = __esm({
14028
14048
  this.generatingStartedAt = 0;
14029
14049
  }
14030
14050
  this.completedDebounceTimer = null;
14031
- }, 2e3);
14051
+ }, 3e3);
14032
14052
  }
14033
14053
  } else if (newStatus === "stopped") {
14034
14054
  if (this.generatingDebounceTimer) {
@@ -55353,7 +55373,7 @@ var init_adhdev_daemon = __esm({
55353
55373
  init_version();
55354
55374
  init_src();
55355
55375
  init_runtime_defaults();
55356
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.8" });
55376
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.10" });
55357
55377
  AdhdevDaemon = class _AdhdevDaemon {
55358
55378
  localHttpServer = null;
55359
55379
  localWss = null;
@@ -55377,6 +55397,7 @@ var init_adhdev_daemon = __esm({
55377
55397
  mandatoryUpgradeInFlight = false;
55378
55398
  debugConfig = resolveDebugRuntimeConfig();
55379
55399
  recentInteractionIdsBySession = /* @__PURE__ */ new Map();
55400
+ ptyInputDropLogLastAt = /* @__PURE__ */ new Map();
55380
55401
  static MANDATORY_UPDATE_BLOCKED_COMMANDS = /* @__PURE__ */ new Set([
55381
55402
  "launch_ide",
55382
55403
  "launch_cli",
@@ -55428,6 +55449,14 @@ var init_adhdev_daemon = __esm({
55428
55449
  const mode = this.getCliPresentationMode(sessionId);
55429
55450
  return mode === "chat" || mode === "terminal";
55430
55451
  }
55452
+ logPtyInputDrop(sessionId, reason) {
55453
+ const key = `${sessionId || "(missing)"}:${reason}`;
55454
+ const now = Date.now();
55455
+ const last = this.ptyInputDropLogLastAt.get(key) || 0;
55456
+ if (now - last < 3e4) return;
55457
+ this.ptyInputDropLogLastAt.set(key, now);
55458
+ LOG.warn("P2P", `PTY input dropped: session=${sessionId || "(missing)"} reason=${reason}`);
55459
+ }
55431
55460
  getUpgradePackageName() {
55432
55461
  return process.argv[1]?.includes("daemon-standalone") ? "@adhdev/daemon-standalone" : "adhdev";
55433
55462
  }
@@ -55540,9 +55569,13 @@ var init_adhdev_daemon = __esm({
55540
55569
  });
55541
55570
  }
55542
55571
  getHotChatSessionIdsForP2PFlush() {
55543
- const snapshot = this.buildLiveStatusSnapshot();
55572
+ const sessions = buildSessionEntries(
55573
+ this.components.instanceManager.collectAllStates(),
55574
+ this.components.cdpManagers,
55575
+ { profile: "live" }
55576
+ );
55544
55577
  const hotSessions = classifyHotChatSessionsForSubscriptionFlush(
55545
- snapshot.sessions,
55578
+ sessions,
55546
55579
  this.hotP2PChatSessionIds
55547
55580
  );
55548
55581
  this.hotP2PChatSessionIds = hotSessions.active;
@@ -55867,10 +55900,23 @@ ${err?.stack || ""}`);
55867
55900
  }
55868
55901
  });
55869
55902
  this.p2p.onPtyInput((sessionId, data) => {
55870
- if (!this.isCliSession(sessionId)) return;
55903
+ if (!this.isCliSession(sessionId)) {
55904
+ this.logPtyInputDrop(sessionId, "not_cli_session");
55905
+ return;
55906
+ }
55871
55907
  const found = this.components.cliManager.findAdapter(sessionId, { instanceKey: sessionId });
55872
- if (found && typeof found.adapter.writeRaw === "function") {
55908
+ if (!found) {
55909
+ this.logPtyInputDrop(sessionId, "adapter_not_found");
55910
+ return;
55911
+ }
55912
+ if (typeof found.adapter.writeRaw !== "function") {
55913
+ this.logPtyInputDrop(sessionId, "writeRaw_missing");
55914
+ return;
55915
+ }
55916
+ try {
55873
55917
  found.adapter.writeRaw(data);
55918
+ } catch {
55919
+ this.logPtyInputDrop(sessionId, "write_failed");
55874
55920
  }
55875
55921
  });
55876
55922
  this.p2p.onPtyResize((sessionId, cols, rows) => {