adhdev 0.8.61 → 0.8.65

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
@@ -1494,6 +1494,51 @@ var init_host_memory = __esm({
1494
1494
  }
1495
1495
  });
1496
1496
 
1497
+ // ../../oss/packages/daemon-core/src/status/chat-tail-hot-sessions.ts
1498
+ function parseMessageTimestamp(value) {
1499
+ if (typeof value === "number" && Number.isFinite(value)) return value;
1500
+ if (typeof value === "string") {
1501
+ const parsed = Date.parse(value);
1502
+ if (Number.isFinite(parsed)) return parsed;
1503
+ }
1504
+ return 0;
1505
+ }
1506
+ function classifyHotChatSessionsForSubscriptionFlush(sessions, previousHotSessionIds, options = {}) {
1507
+ const now = options.now ?? Date.now();
1508
+ const recentMessageGraceMs = Math.max(
1509
+ 0,
1510
+ Number.isFinite(options.recentMessageGraceMs) ? Number(options.recentMessageGraceMs) : DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS
1511
+ );
1512
+ const activeStatuses = options.activeStatuses ?? DEFAULT_ACTIVE_CHAT_POLL_STATUSES;
1513
+ const active = /* @__PURE__ */ new Set();
1514
+ for (const session of sessions) {
1515
+ const sessionId = typeof session?.id === "string" ? session.id : "";
1516
+ if (!sessionId) continue;
1517
+ const status = String(session?.status || "").toLowerCase();
1518
+ const lastMessageAt = parseMessageTimestamp(session?.lastMessageAt);
1519
+ const recentlyUpdated = lastMessageAt > 0 && now - lastMessageAt <= recentMessageGraceMs;
1520
+ if (activeStatuses.has(status) || recentlyUpdated) {
1521
+ active.add(sessionId);
1522
+ }
1523
+ }
1524
+ const finalizing = new Set(
1525
+ Array.from(previousHotSessionIds).filter((sessionId) => !active.has(sessionId))
1526
+ );
1527
+ return { active, finalizing };
1528
+ }
1529
+ var DEFAULT_ACTIVE_CHAT_POLL_STATUSES, DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS;
1530
+ var init_chat_tail_hot_sessions = __esm({
1531
+ "../../oss/packages/daemon-core/src/status/chat-tail-hot-sessions.ts"() {
1532
+ "use strict";
1533
+ DEFAULT_ACTIVE_CHAT_POLL_STATUSES = /* @__PURE__ */ new Set([
1534
+ "generating",
1535
+ "waiting_approval",
1536
+ "starting"
1537
+ ]);
1538
+ DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS = 8e3;
1539
+ }
1540
+ });
1541
+
1497
1542
  // ../../oss/packages/daemon-core/src/logging/logger.ts
1498
1543
  function setLogLevel(level) {
1499
1544
  currentLevel = level;
@@ -3359,19 +3404,75 @@ var init_status_monitor = __esm({
3359
3404
  });
3360
3405
 
3361
3406
  // ../../oss/packages/daemon-core/src/providers/chat-message-normalization.ts
3407
+ function canonicalizeKindHint(value) {
3408
+ return value.trim().toLowerCase().replace(/[\s-]+/g, "_");
3409
+ }
3410
+ function resolveBuiltinOrAliasKind(kind) {
3411
+ if (typeof kind !== "string") return null;
3412
+ const normalizedKind = canonicalizeKindHint(kind);
3413
+ if (!normalizedKind) return null;
3414
+ if (KNOWN_CHAT_MESSAGE_KINDS.has(normalizedKind)) return normalizedKind;
3415
+ return CHAT_MESSAGE_KIND_ALIASES[normalizedKind] || null;
3416
+ }
3417
+ function inferHintKind(value) {
3418
+ const direct = resolveBuiltinOrAliasKind(value);
3419
+ if (direct) return direct;
3420
+ if (typeof value !== "string") return null;
3421
+ const normalized = canonicalizeKindHint(value);
3422
+ if (!normalized) return null;
3423
+ if (/thought|thinking|reasoning/.test(normalized)) return "thought";
3424
+ if (/tool/.test(normalized)) return "tool";
3425
+ if (/terminal|command|shell|console/.test(normalized)) return "terminal";
3426
+ return null;
3427
+ }
3428
+ function inferKindFromToolCalls(message) {
3429
+ const toolCalls = Array.isArray(message?.toolCalls) ? message.toolCalls : [];
3430
+ if (toolCalls.length === 0) return null;
3431
+ if (toolCalls.some((toolCall) => toolCall?.kind === "think")) return "thought";
3432
+ if (toolCalls.some((toolCall) => toolCall?.kind === "execute")) return "terminal";
3433
+ if (toolCalls.some((toolCall) => Array.isArray(toolCall?.content) && toolCall.content.some((entry) => entry?.type === "terminal"))) {
3434
+ return "terminal";
3435
+ }
3436
+ return "tool";
3437
+ }
3438
+ function inferMissingChatMessageKind(message) {
3439
+ const role = typeof message?.role === "string" ? message.role.trim().toLowerCase() : "";
3440
+ if (role === "system") return "system";
3441
+ const meta3 = message?.meta && typeof message.meta === "object" ? message.meta : void 0;
3442
+ const hintCandidates = [
3443
+ message?._sub,
3444
+ message?._type,
3445
+ meta3?.label,
3446
+ typeof message?.senderName === "string" ? message.senderName : void 0
3447
+ ];
3448
+ for (const candidate of hintCandidates) {
3449
+ const inferred = inferHintKind(candidate);
3450
+ if (inferred) return inferred;
3451
+ }
3452
+ const inferredFromToolCalls = inferKindFromToolCalls(message);
3453
+ if (inferredFromToolCalls) return inferredFromToolCalls;
3454
+ return null;
3455
+ }
3362
3456
  function isBuiltinChatMessageKind(kind) {
3363
- return typeof kind === "string" && KNOWN_CHAT_MESSAGE_KINDS.has(kind.trim().toLowerCase());
3457
+ return resolveBuiltinOrAliasKind(kind) !== null;
3364
3458
  }
3365
3459
  function normalizeChatMessageKind(kind, role) {
3366
- const normalizedKind = typeof kind === "string" ? kind.trim().toLowerCase() : "";
3367
- if (normalizedKind && KNOWN_CHAT_MESSAGE_KINDS.has(normalizedKind)) return normalizedKind;
3460
+ const resolvedKind = resolveBuiltinOrAliasKind(kind);
3461
+ if (resolvedKind) return resolvedKind;
3368
3462
  const normalizedRole = typeof role === "string" ? role.trim().toLowerCase() : "";
3369
3463
  return normalizedRole === "system" ? "system" : "standard";
3370
3464
  }
3465
+ function resolveChatMessageKind(message) {
3466
+ const explicitKind = resolveBuiltinOrAliasKind(message?.kind);
3467
+ if (explicitKind) return explicitKind;
3468
+ const inferredKind = inferMissingChatMessageKind(message);
3469
+ if (inferredKind) return inferredKind;
3470
+ return normalizeChatMessageKind(message?.kind, message?.role);
3471
+ }
3371
3472
  function buildChatMessage(message) {
3372
3473
  return {
3373
3474
  ...message,
3374
- kind: normalizeChatMessageKind(message?.kind, message?.role)
3475
+ kind: resolveChatMessageKind(message)
3375
3476
  };
3376
3477
  }
3377
3478
  function buildSystemChatMessage(message) {
@@ -3394,6 +3495,24 @@ function buildAssistantChatMessage(message) {
3394
3495
  kind: message?.kind || "standard"
3395
3496
  });
3396
3497
  }
3498
+ function buildThoughtChatMessage(message) {
3499
+ return buildAssistantChatMessage({
3500
+ ...message,
3501
+ kind: message?.kind || "thought"
3502
+ });
3503
+ }
3504
+ function buildToolChatMessage(message) {
3505
+ return buildAssistantChatMessage({
3506
+ ...message,
3507
+ kind: message?.kind || "tool"
3508
+ });
3509
+ }
3510
+ function buildTerminalChatMessage(message) {
3511
+ return buildAssistantChatMessage({
3512
+ ...message,
3513
+ kind: message?.kind || "terminal"
3514
+ });
3515
+ }
3397
3516
  function buildUserChatMessage(message) {
3398
3517
  return buildChatMessage({
3399
3518
  ...message,
@@ -3407,12 +3526,30 @@ function normalizeChatMessage(message) {
3407
3526
  function normalizeChatMessages(messages) {
3408
3527
  return (Array.isArray(messages) ? messages : []).map((message) => normalizeChatMessage(message));
3409
3528
  }
3410
- var BUILTIN_CHAT_MESSAGE_KINDS, KNOWN_CHAT_MESSAGE_KINDS;
3529
+ var BUILTIN_CHAT_MESSAGE_KINDS, KNOWN_CHAT_MESSAGE_KINDS, CHAT_MESSAGE_KIND_ALIASES;
3411
3530
  var init_chat_message_normalization = __esm({
3412
3531
  "../../oss/packages/daemon-core/src/providers/chat-message-normalization.ts"() {
3413
3532
  "use strict";
3414
3533
  BUILTIN_CHAT_MESSAGE_KINDS = ["standard", "thought", "tool", "terminal", "system"];
3415
3534
  KNOWN_CHAT_MESSAGE_KINDS = new Set(BUILTIN_CHAT_MESSAGE_KINDS);
3535
+ CHAT_MESSAGE_KIND_ALIASES = {
3536
+ text: "standard",
3537
+ message: "standard",
3538
+ assistant: "standard",
3539
+ thinking: "thought",
3540
+ think: "thought",
3541
+ reasoning: "thought",
3542
+ reason: "thought",
3543
+ toolcall: "tool",
3544
+ tool_call: "tool",
3545
+ tooluse: "tool",
3546
+ tool_use: "tool",
3547
+ action: "tool",
3548
+ command: "terminal",
3549
+ cmd: "terminal",
3550
+ shell: "terminal",
3551
+ console: "terminal"
3552
+ };
3416
3553
  }
3417
3554
  });
3418
3555
 
@@ -4897,11 +5034,13 @@ var init_ide_provider_instance = __esm({
4897
5034
  if (pm.receivedAt) prevByHash.set(h, pm.receivedAt);
4898
5035
  }
4899
5036
  const now = Date.now();
4900
- const messages = chat.messages || [];
4901
- for (const msg of messages) {
5037
+ const rawMessages = chat.messages || [];
5038
+ for (const msg of rawMessages) {
4902
5039
  const h = `${msg.role}:${(msg.content || "").slice(0, 100)}`;
4903
5040
  msg.receivedAt = prevByHash.get(h) || now;
4904
5041
  }
5042
+ chat.messages = normalizeChatMessages(rawMessages);
5043
+ const messages = chat.messages || [];
4905
5044
  if (messages.length > 0) {
4906
5045
  const hiddenKinds = /* @__PURE__ */ new Set();
4907
5046
  if (this.settings.showThinking === false) hiddenKinds.add("thought");
@@ -10508,6 +10647,7 @@ function buildCliParseInput(options) {
10508
10647
  terminalScreenText,
10509
10648
  baseMessages,
10510
10649
  partialResponse,
10650
+ isWaitingForResponse,
10511
10651
  scope,
10512
10652
  runtimeSettings
10513
10653
  } = options;
@@ -10525,6 +10665,7 @@ function buildCliParseInput(options) {
10525
10665
  recentScreen: buildCliScreenSnapshot(recentBuffer),
10526
10666
  messages: [...baseMessages],
10527
10667
  partialResponse,
10668
+ isWaitingForResponse,
10528
10669
  promptText: scope?.prompt || "",
10529
10670
  settings: { ...runtimeSettings }
10530
10671
  };
@@ -11263,6 +11404,18 @@ var init_provider_cli_adapter = __esm({
11263
11404
  const holdMs = this.getStatusActivityHoldMs();
11264
11405
  return quietForMs < holdMs || screenStableMs < holdMs;
11265
11406
  }
11407
+ shouldDeferIdleTimeoutFinish() {
11408
+ if (!this.isWaitingForResponse || this.currentStatus === "waiting_approval") {
11409
+ return false;
11410
+ }
11411
+ const latestStatus = this.runDetectStatus(this.recentOutputBuffer) || this.currentStatus;
11412
+ if (latestStatus === "generating") {
11413
+ this.settledBuffer = this.recentOutputBuffer;
11414
+ this.evaluateSettled();
11415
+ return true;
11416
+ }
11417
+ return false;
11418
+ }
11266
11419
  getStartupConfirmationModal(screenText) {
11267
11420
  const text = sanitizeTerminalText(String(screenText || ""));
11268
11421
  if (!text.trim()) return null;
@@ -11421,6 +11574,7 @@ var init_provider_cli_adapter = __esm({
11421
11574
  if (this.idleTimeout) clearTimeout(this.idleTimeout);
11422
11575
  this.idleTimeout = setTimeout(() => {
11423
11576
  if (this.isWaitingForResponse && this.currentStatus !== "waiting_approval") {
11577
+ if (this.shouldDeferIdleTimeoutFinish()) return;
11424
11578
  this.finishResponse();
11425
11579
  }
11426
11580
  }, this.timeouts.generatingIdle);
@@ -11456,6 +11610,7 @@ var init_provider_cli_adapter = __esm({
11456
11610
  if (this.idleTimeout) clearTimeout(this.idleTimeout);
11457
11611
  this.idleTimeout = setTimeout(() => {
11458
11612
  if (this.isWaitingForResponse && this.currentStatus !== "waiting_approval") {
11613
+ if (this.shouldDeferIdleTimeoutFinish()) return;
11459
11614
  this.finishResponse();
11460
11615
  }
11461
11616
  }, this.timeouts.generatingIdle);
@@ -11498,7 +11653,10 @@ var init_provider_cli_adapter = __esm({
11498
11653
  this.setStatus("generating", "script_detect");
11499
11654
  if (this.idleTimeout) clearTimeout(this.idleTimeout);
11500
11655
  this.idleTimeout = setTimeout(() => {
11501
- if (this.isWaitingForResponse) this.finishResponse();
11656
+ if (this.isWaitingForResponse) {
11657
+ if (this.shouldDeferIdleTimeoutFinish()) return;
11658
+ this.finishResponse();
11659
+ }
11502
11660
  }, this.timeouts.generatingIdle);
11503
11661
  this.onStatusChange?.();
11504
11662
  return;
@@ -11566,6 +11724,7 @@ var init_provider_cli_adapter = __esm({
11566
11724
  if (this.idleTimeout) clearTimeout(this.idleTimeout);
11567
11725
  this.idleTimeout = setTimeout(() => {
11568
11726
  if (this.isWaitingForResponse && this.currentStatus !== "waiting_approval") {
11727
+ if (this.shouldDeferIdleTimeoutFinish()) return;
11569
11728
  this.clearIdleFinishCandidate("idle_timeout_finish");
11570
11729
  this.finishResponse();
11571
11730
  }
@@ -11704,6 +11863,7 @@ var init_provider_cli_adapter = __esm({
11704
11863
  tail: text.slice(-500),
11705
11864
  screenText,
11706
11865
  rawBuffer: this.accumulatedRawBuffer,
11866
+ isWaitingForResponse: this.isWaitingForResponse,
11707
11867
  screen: buildCliScreenSnapshot(screenText),
11708
11868
  tailScreen: buildCliScreenSnapshot(text.slice(-500))
11709
11869
  });
@@ -11813,6 +11973,7 @@ var init_provider_cli_adapter = __esm({
11813
11973
  terminalScreenText: this.terminalScreen.getText(),
11814
11974
  baseMessages: this.committedMessages,
11815
11975
  partialResponse: this.responseBuffer,
11976
+ isWaitingForResponse: this.isWaitingForResponse,
11816
11977
  scope: this.currentTurnScope,
11817
11978
  runtimeSettings: this.runtimeSettings
11818
11979
  });
@@ -11831,6 +11992,7 @@ var init_provider_cli_adapter = __esm({
11831
11992
  terminalScreenText: this.terminalScreen.getText(),
11832
11993
  baseMessages,
11833
11994
  partialResponse,
11995
+ isWaitingForResponse: this.isWaitingForResponse,
11834
11996
  scope,
11835
11997
  runtimeSettings: this.runtimeSettings
11836
11998
  });
@@ -29610,6 +29772,7 @@ var init_acp_provider_instance = __esm({
29610
29772
  activeToolCalls = [];
29611
29773
  stopReason = null;
29612
29774
  partialContent = "";
29775
+ partialThoughtContent = "";
29613
29776
  /** Rich content blocks accumulated during streaming */
29614
29777
  partialBlocks = [];
29615
29778
  /** Tool calls collected during current turn */
@@ -29655,6 +29818,10 @@ var init_acp_provider_instance = __esm({
29655
29818
  content
29656
29819
  });
29657
29820
  }));
29821
+ if (this.currentStatus === "generating") {
29822
+ const partialThoughtMessage = this.buildPartialThoughtMessage(Date.now());
29823
+ if (partialThoughtMessage) recentMessages.push(partialThoughtMessage);
29824
+ }
29658
29825
  if (this.currentStatus === "generating" && (this.partialContent || this.partialBlocks.length > 0)) {
29659
29826
  const blocks = this.buildPartialBlocks();
29660
29827
  if (blocks.length > 0) {
@@ -30213,6 +30380,7 @@ var init_acp_provider_instance = __esm({
30213
30380
  }));
30214
30381
  this.currentStatus = "generating";
30215
30382
  this.partialContent = "";
30383
+ this.partialThoughtContent = "";
30216
30384
  this.partialBlocks = [];
30217
30385
  this.turnToolCalls = [];
30218
30386
  this.detectStatusTransition();
@@ -30295,7 +30463,14 @@ var init_acp_provider_instance = __esm({
30295
30463
  this.currentStatus = "generating";
30296
30464
  break;
30297
30465
  }
30298
- case "agent_thought_chunk":
30466
+ case "agent_thought_chunk": {
30467
+ const content = update.content;
30468
+ if (content?.type === "text" && typeof content.text === "string") {
30469
+ this.partialThoughtContent += content.text;
30470
+ }
30471
+ this.currentStatus = "generating";
30472
+ break;
30473
+ }
30299
30474
  case "user_message_chunk": {
30300
30475
  break;
30301
30476
  }
@@ -30450,8 +30625,82 @@ var init_acp_provider_instance = __esm({
30450
30625
  blocks.push(...this.partialBlocks);
30451
30626
  return blocks;
30452
30627
  }
30628
+ buildPartialThoughtMessage(timestamp = Date.now()) {
30629
+ const content = this.partialThoughtContent.trim();
30630
+ if (!content) return null;
30631
+ return buildThoughtChatMessage({
30632
+ content,
30633
+ timestamp,
30634
+ meta: {
30635
+ label: "Thought",
30636
+ isRunning: this.currentStatus === "generating"
30637
+ }
30638
+ });
30639
+ }
30640
+ buildToolCallBubbleKind(toolCall) {
30641
+ if (toolCall.kind === "think") return "thought";
30642
+ if (toolCall.kind === "execute") return "terminal";
30643
+ if (Array.isArray(toolCall.content) && toolCall.content.some((entry) => entry?.type === "terminal")) return "terminal";
30644
+ return "tool";
30645
+ }
30646
+ summarizeToolCallBubbleContent(toolCall) {
30647
+ const rawOutput = typeof toolCall.rawOutput === "string" ? toolCall.rawOutput.trim() : toolCall.rawOutput != null ? JSON.stringify(toolCall.rawOutput) : "";
30648
+ if (rawOutput) return rawOutput;
30649
+ const contentText = Array.isArray(toolCall.content) ? toolCall.content.map((entry) => {
30650
+ if (!entry || typeof entry !== "object") return "";
30651
+ if (entry.type === "content") return flattenContent([entry.content]).trim();
30652
+ if (entry.type === "diff") return `${entry.path}
30653
+ ${entry.newText || ""}`.trim();
30654
+ if (entry.type === "terminal") return `Terminal: ${entry.terminalId || ""}`.trim();
30655
+ return "";
30656
+ }).filter(Boolean).join("\n\n").trim() : "";
30657
+ if (contentText) return contentText;
30658
+ const rawInput = typeof toolCall.rawInput === "string" ? toolCall.rawInput.trim() : toolCall.rawInput != null ? JSON.stringify(toolCall.rawInput) : "";
30659
+ if (rawInput) {
30660
+ return toolCall.title ? `${toolCall.title}
30661
+ ${rawInput}` : rawInput;
30662
+ }
30663
+ return toolCall.title || "";
30664
+ }
30665
+ buildTurnToolCallMessages(timestamp = Date.now()) {
30666
+ return this.turnToolCalls.map((toolCall) => {
30667
+ const content = this.summarizeToolCallBubbleContent(toolCall);
30668
+ if (!content) return null;
30669
+ const isRunning = toolCall.status === "pending" || toolCall.status === "in_progress";
30670
+ const label = toolCall.title || void 0;
30671
+ const kind = this.buildToolCallBubbleKind(toolCall);
30672
+ if (kind === "thought") {
30673
+ return buildThoughtChatMessage({
30674
+ content,
30675
+ timestamp,
30676
+ meta: { label: label || "Thought", isRunning }
30677
+ });
30678
+ }
30679
+ if (kind === "terminal") {
30680
+ return buildTerminalChatMessage({
30681
+ content,
30682
+ timestamp,
30683
+ meta: { label: label || "Ran command", isRunning }
30684
+ });
30685
+ }
30686
+ return buildToolChatMessage({
30687
+ content,
30688
+ timestamp,
30689
+ meta: { label: label || "Tool call", isRunning }
30690
+ });
30691
+ }).filter(Boolean);
30692
+ }
30453
30693
  /** Finalize streaming content into an assistant message */
30454
30694
  finalizeAssistantMessage() {
30695
+ const timestamp = Date.now();
30696
+ const thoughtMessage = this.buildPartialThoughtMessage(timestamp);
30697
+ if (thoughtMessage) {
30698
+ this.messages.push(thoughtMessage);
30699
+ }
30700
+ const toolCallMessages = this.buildTurnToolCallMessages(timestamp);
30701
+ if (toolCallMessages.length > 0) {
30702
+ this.messages.push(...toolCallMessages);
30703
+ }
30455
30704
  const blocks = this.buildPartialBlocks();
30456
30705
  const finalBlocks = blocks.map((b) => {
30457
30706
  if (b.type === "text" && b.text.endsWith("...")) {
@@ -30467,6 +30716,7 @@ var init_acp_provider_instance = __esm({
30467
30716
  }));
30468
30717
  }
30469
30718
  this.partialContent = "";
30719
+ this.partialThoughtContent = "";
30470
30720
  this.partialBlocks = [];
30471
30721
  this.turnToolCalls = [];
30472
30722
  }
@@ -35105,6 +35355,9 @@ function parseMessageTime(value) {
35105
35355
  }
35106
35356
  return 0;
35107
35357
  }
35358
+ function getMessageEventTime(message) {
35359
+ return parseMessageTime(message?.receivedAt) || parseMessageTime(message?.timestamp) || 0;
35360
+ }
35108
35361
  function stringifyPreviewContent(content) {
35109
35362
  if (typeof content === "string") return content;
35110
35363
  if (Array.isArray(content)) {
@@ -35149,7 +35402,7 @@ function getLastDisplayMessage(session) {
35149
35402
  return {
35150
35403
  role,
35151
35404
  preview,
35152
- receivedAt: parseMessageTime(candidate?.receivedAt),
35405
+ receivedAt: getMessageEventTime(candidate),
35153
35406
  hash: simplePreviewHash(`${role}:${preview}`)
35154
35407
  };
35155
35408
  }
@@ -35158,7 +35411,7 @@ function getLastDisplayMessage(session) {
35158
35411
  function getSessionMessageUpdatedAt(session) {
35159
35412
  const lastMessage = session.activeChat?.messages?.at?.(-1);
35160
35413
  if (!lastMessage) return 0;
35161
- return parseMessageTime(lastMessage.receivedAt) || 0;
35414
+ return getMessageEventTime(lastMessage);
35162
35415
  }
35163
35416
  function getSessionCompletionMarker(session) {
35164
35417
  const lastMessage = session.activeChat?.messages?.at?.(-1);
@@ -35168,7 +35421,7 @@ function getSessionCompletionMarker(session) {
35168
35421
  if (typeof lastMessage._turnKey === "string" && lastMessage._turnKey) return `turn:${lastMessage._turnKey}`;
35169
35422
  if (typeof lastMessage.id === "string" && lastMessage.id) return `id:${lastMessage.id}`;
35170
35423
  if (typeof lastMessage.index === "number" && Number.isFinite(lastMessage.index)) return `idx:${lastMessage.index}`;
35171
- const timestamp = parseMessageTime(lastMessage.receivedAt);
35424
+ const timestamp = getMessageEventTime(lastMessage);
35172
35425
  return timestamp > 0 ? `ts:${timestamp}` : "";
35173
35426
  }
35174
35427
  function getSessionLastUsedAt(session) {
@@ -36501,6 +36754,7 @@ var init_provider_adapter = __esm({
36501
36754
  "use strict";
36502
36755
  init_control_effects();
36503
36756
  init_provider_patch_state();
36757
+ init_chat_message_normalization();
36504
36758
  ProviderStreamAdapter = class {
36505
36759
  agentType;
36506
36760
  agentName;
@@ -36610,7 +36864,7 @@ var init_provider_adapter = __esm({
36610
36864
  agentName: this.agentName,
36611
36865
  extensionId: this.extensionId,
36612
36866
  status: data.status || "idle",
36613
- messages: data.messages || [],
36867
+ messages: normalizeChatMessages(Array.isArray(data.messages) ? data.messages : []),
36614
36868
  inputContent: data.inputContent || "",
36615
36869
  activeModal: data.activeModal
36616
36870
  };
@@ -43881,6 +44135,8 @@ __export(src_exports, {
43881
44135
  CdpDomHandlers: () => CdpDomHandlers,
43882
44136
  CliProviderInstance: () => CliProviderInstance,
43883
44137
  DAEMON_WS_PATH: () => DAEMON_WS_PATH,
44138
+ DEFAULT_ACTIVE_CHAT_POLL_STATUSES: () => DEFAULT_ACTIVE_CHAT_POLL_STATUSES,
44139
+ DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS: () => DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS,
43884
44140
  DEFAULT_DAEMON_PORT: () => DEFAULT_DAEMON_PORT,
43885
44141
  DEFAULT_SESSION_HOST_APP_NAME: () => DEFAULT_SESSION_HOST_APP_NAME,
43886
44142
  DEFAULT_STANDALONE_SESSION_HOST_APP_NAME: () => DEFAULT_STANDALONE_SESSION_HOST_APP_NAME,
@@ -43909,7 +44165,11 @@ __export(src_exports, {
43909
44165
  buildSessionEntries: () => buildSessionEntries,
43910
44166
  buildStatusSnapshot: () => buildStatusSnapshot,
43911
44167
  buildSystemChatMessage: () => buildSystemChatMessage,
44168
+ buildTerminalChatMessage: () => buildTerminalChatMessage,
44169
+ buildThoughtChatMessage: () => buildThoughtChatMessage,
44170
+ buildToolChatMessage: () => buildToolChatMessage,
43912
44171
  buildUserChatMessage: () => buildUserChatMessage,
44172
+ classifyHotChatSessionsForSubscriptionFlush: () => classifyHotChatSessionsForSubscriptionFlush,
43913
44173
  clearDebugTrace: () => clearDebugTrace,
43914
44174
  configureDebugTraceStore: () => configureDebugTraceStore,
43915
44175
  connectCdpManager: () => connectCdpManager,
@@ -43976,6 +44236,7 @@ __export(src_exports, {
43976
44236
  resetConfig: () => resetConfig,
43977
44237
  resetDebugRuntimeConfig: () => resetDebugRuntimeConfig,
43978
44238
  resetState: () => resetState,
44239
+ resolveChatMessageKind: () => resolveChatMessageKind,
43979
44240
  resolveDebugRuntimeConfig: () => resolveDebugRuntimeConfig,
43980
44241
  resolveSessionHostAppName: () => resolveSessionHostAppName,
43981
44242
  saveConfig: () => saveConfig,
@@ -44002,6 +44263,7 @@ var init_src = __esm({
44002
44263
  init_ide_detector();
44003
44264
  init_cli_detector();
44004
44265
  init_host_memory();
44266
+ init_chat_tail_hot_sessions();
44005
44267
  init_manager();
44006
44268
  init_devtools();
44007
44269
  init_setup();
@@ -84084,7 +84346,7 @@ function stopDaemon(ref = {}) {
84084
84346
  return false;
84085
84347
  }
84086
84348
  }
84087
- var os28, fs23, path30, import_http, import_ws3, pkgVersion, ACTIVE_CHAT_POLL_STATUSES, AdhdevDaemon;
84349
+ var os28, fs23, path30, import_http, import_ws3, pkgVersion, AdhdevDaemon;
84088
84350
  var init_adhdev_daemon = __esm({
84089
84351
  "src/adhdev-daemon.ts"() {
84090
84352
  "use strict";
@@ -84103,12 +84365,8 @@ var init_adhdev_daemon = __esm({
84103
84365
  import_ws3 = require("ws");
84104
84366
  init_source();
84105
84367
  init_version();
84106
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.61" });
84107
- ACTIVE_CHAT_POLL_STATUSES = /* @__PURE__ */ new Set([
84108
- "generating",
84109
- "waiting_approval",
84110
- "starting"
84111
- ]);
84368
+ init_src();
84369
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.8.65" });
84112
84370
  AdhdevDaemon = class _AdhdevDaemon {
84113
84371
  localHttpServer = null;
84114
84372
  localWss = null;
@@ -84335,14 +84593,12 @@ var init_adhdev_daemon = __esm({
84335
84593
  }
84336
84594
  getHotChatSessionIdsForP2PFlush() {
84337
84595
  const snapshot = this.buildLiveStatusSnapshot();
84338
- const active = new Set(
84339
- snapshot.sessions.filter((session) => ACTIVE_CHAT_POLL_STATUSES.has(String(session.status || "").toLowerCase())).map((session) => session.id)
84340
- );
84341
- const finalizing = new Set(
84342
- Array.from(this.hotP2PChatSessionIds).filter((sessionId) => !active.has(sessionId))
84596
+ const hotSessions = classifyHotChatSessionsForSubscriptionFlush(
84597
+ snapshot.sessions,
84598
+ this.hotP2PChatSessionIds
84343
84599
  );
84344
- this.hotP2PChatSessionIds = active;
84345
- return { active, finalizing };
84600
+ this.hotP2PChatSessionIds = hotSessions.active;
84601
+ return hotSessions;
84346
84602
  }
84347
84603
  async flushP2PChatSubscriptions(options = {}) {
84348
84604
  if (!this.p2p?.isConnected || !this.p2p.hasChatSubscriptions()) return;