@adhdev/daemon-core 0.9.31 → 0.9.32

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.mjs CHANGED
@@ -348,14 +348,13 @@ function daemonLog(category, msg, level = "info") {
348
348
  const shouldOutput = LEVEL_NUM[level] >= LEVEL_NUM[currentLevel];
349
349
  const label = LEVEL_LABEL[level];
350
350
  const line = `[${ts()}] [${label}] [${category}] ${msg}`;
351
+ if (!shouldOutput) return;
351
352
  writeToFile(line);
352
353
  ringBuffer.push({ ts: Date.now(), level, category, message: msg });
353
354
  if (ringBuffer.length > RING_BUFFER_SIZE) {
354
355
  ringBuffer.splice(0, ringBuffer.length - RING_BUFFER_SIZE);
355
356
  }
356
- if (shouldOutput) {
357
- origConsoleLog(line);
358
- }
357
+ origConsoleLog(line);
359
358
  }
360
359
  function installGlobalInterceptor() {
361
360
  if (interceptorInstalled) return;
@@ -2161,6 +2160,7 @@ var init_provider_cli_adapter = __esm({
2161
2160
  static STATUS_HOT_PATH_PARSE_MIN_INTERVAL_MS = 1e3;
2162
2161
  static SCREEN_SNAPSHOT_MIN_INTERVAL_MS = 250;
2163
2162
  static MAX_TRACE_ENTRIES = 250;
2163
+ static PARSE_MESSAGE_TAIL_LIMIT = 100;
2164
2164
  providerResolutionMeta;
2165
2165
  static FINISH_RETRY_DELAY_MS = 300;
2166
2166
  static MAX_FINISH_RETRIES = 2;
@@ -2192,6 +2192,32 @@ var init_provider_cli_adapter = __esm({
2192
2192
  }
2193
2193
  return null;
2194
2194
  }
2195
+ selectParseBaseMessages(baseMessages) {
2196
+ if (baseMessages.length <= _ProviderCliAdapter.PARSE_MESSAGE_TAIL_LIMIT) return baseMessages;
2197
+ return baseMessages.slice(-_ProviderCliAdapter.PARSE_MESSAGE_TAIL_LIMIT);
2198
+ }
2199
+ messagesComparable(left, right) {
2200
+ if (!left || !right) return false;
2201
+ if ((left.role || "") !== (right.role || "")) return false;
2202
+ const leftText = normalizeComparableTranscriptText(left.content);
2203
+ const rightText = normalizeComparableTranscriptText(right.content);
2204
+ return !!leftText && leftText === rightText;
2205
+ }
2206
+ stitchParsedMessagesWithCommittedBase(parsedMessages, fullBaseMessages, parseBaseMessages) {
2207
+ if (!Array.isArray(parsedMessages) || parsedMessages.length === 0) return parsedMessages;
2208
+ if (fullBaseMessages.length <= parseBaseMessages.length) return parsedMessages;
2209
+ const parsedFirst = parsedMessages[0];
2210
+ const fullFirst = fullBaseMessages[0];
2211
+ if (parsedMessages.length >= fullBaseMessages.length && this.messagesComparable(parsedFirst, fullFirst)) {
2212
+ return parsedMessages;
2213
+ }
2214
+ const tailFirst = parseBaseMessages[0];
2215
+ if (tailFirst && this.messagesComparable(parsedFirst, tailFirst)) {
2216
+ const prefixLength = fullBaseMessages.length - parseBaseMessages.length;
2217
+ return [...fullBaseMessages.slice(0, prefixLength), ...parsedMessages];
2218
+ }
2219
+ return [...fullBaseMessages, ...parsedMessages];
2220
+ }
2195
2221
  getIdleFinishConfirmMs() {
2196
2222
  return this.timeouts.idleFinishConfirm;
2197
2223
  }
@@ -2777,7 +2803,7 @@ var init_provider_cli_adapter = __esm({
2777
2803
  const ctx = { now, modal, status, parsedMessages, lastParsedAssistant, parsedStatus: parsedStatus || null, prevStatus };
2778
2804
  if (!this.applyPendingScriptStatusDebounce(ctx)) return;
2779
2805
  const recentInteractiveActivity = this.hasRecentInteractiveActivity(now);
2780
- LOG.info(
2806
+ LOG.debug(
2781
2807
  "CLI",
2782
2808
  `[${this.cliType}] settled diagnostics prompt=${JSON.stringify(this.currentTurnScope?.prompt || "").slice(0, 140)} status=${String(status || "")} parsedStatus=${String(parsedStatus || "")} parsedMsgCount=${parsedMessages.length} lastParsedAssistant=${JSON.stringify(summarizeCliTraceText(lastParsedAssistant?.content || "", 120)).slice(0, 160)} responseBuffer=${JSON.stringify(summarizeCliTraceText(this.responseBuffer, 160)).slice(0, 220)} screen=${JSON.stringify(summarizeCliTraceText(screenText, 160)).slice(0, 220)}`
2783
2809
  );
@@ -3144,18 +3170,26 @@ var init_provider_cli_adapter = __esm({
3144
3170
  try {
3145
3171
  const screenText = this.terminalScreen.getText();
3146
3172
  const tail = this.recentOutputBuffer.slice(-500);
3173
+ const parseBaseMessages = this.selectParseBaseMessages(this.committedMessages);
3147
3174
  const input = buildCliParseInput({
3148
3175
  accumulatedBuffer: this.accumulatedBuffer,
3149
3176
  accumulatedRawBuffer: this.accumulatedRawBuffer,
3150
3177
  recentOutputBuffer: this.recentOutputBuffer,
3151
3178
  terminalScreenText: screenText,
3152
- baseMessages: this.committedMessages,
3179
+ baseMessages: parseBaseMessages,
3153
3180
  partialResponse: this.responseBuffer,
3154
3181
  isWaitingForResponse: this.isWaitingForResponse,
3155
3182
  scope: this.currentTurnScope,
3156
3183
  runtimeSettings: this.runtimeSettings
3157
3184
  });
3158
3185
  const session = this.cliScripts.parseSession({ ...input, tail, tailScreen: buildCliScreenSnapshot(tail) });
3186
+ if (session && typeof session === "object" && Array.isArray(session.messages)) {
3187
+ session.messages = this.stitchParsedMessagesWithCommittedBase(
3188
+ session.messages,
3189
+ this.committedMessages,
3190
+ parseBaseMessages
3191
+ );
3192
+ }
3159
3193
  this.parseErrorMessage = null;
3160
3194
  return session && typeof session === "object" ? session : null;
3161
3195
  } catch (e) {
@@ -3476,12 +3510,13 @@ var init_provider_cli_adapter = __esm({
3476
3510
  }
3477
3511
  try {
3478
3512
  const screenText = typeof screenTextOverride === "string" ? screenTextOverride : this.terminalScreen.getText();
3513
+ const parseBaseMessages = this.selectParseBaseMessages(baseMessages);
3479
3514
  const input = buildCliParseInput({
3480
3515
  accumulatedBuffer: this.accumulatedBuffer,
3481
3516
  accumulatedRawBuffer: this.accumulatedRawBuffer,
3482
3517
  recentOutputBuffer: this.recentOutputBuffer,
3483
3518
  terminalScreenText: screenText,
3484
- baseMessages,
3519
+ baseMessages: parseBaseMessages,
3485
3520
  partialResponse,
3486
3521
  isWaitingForResponse: this.isWaitingForResponse,
3487
3522
  scope,
@@ -3493,6 +3528,11 @@ var init_provider_cli_adapter = __esm({
3493
3528
  }
3494
3529
  const normalizedParsed = this.suppressStaleParsedApproval(parsed, input.recentBuffer, input.screenText);
3495
3530
  if (normalizedParsed && Array.isArray(normalizedParsed.messages)) {
3531
+ normalizedParsed.messages = this.stitchParsedMessagesWithCommittedBase(
3532
+ normalizedParsed.messages,
3533
+ baseMessages,
3534
+ parseBaseMessages
3535
+ );
3496
3536
  this.trimLastAssistantEcho(normalizedParsed.messages, scope?.prompt || getLastUserPromptText(baseMessages));
3497
3537
  }
3498
3538
  this.parseErrorMessage = null;
@@ -4993,6 +5033,7 @@ function classifyHotChatSessionsForSubscriptionFlush(sessions, previousHotSessio
4993
5033
  Number.isFinite(options.recentMessageGraceMs) ? Number(options.recentMessageGraceMs) : DEFAULT_CHAT_TAIL_RECENT_MESSAGE_GRACE_MS
4994
5034
  );
4995
5035
  const activeStatuses = options.activeStatuses ?? DEFAULT_ACTIVE_CHAT_POLL_STATUSES;
5036
+ const activeSessionIds = options.activeSessionIds ?? /* @__PURE__ */ new Set();
4996
5037
  const active = /* @__PURE__ */ new Set();
4997
5038
  const excluded = /* @__PURE__ */ new Set();
4998
5039
  for (const session of sessions) {
@@ -5002,6 +5043,10 @@ function classifyHotChatSessionsForSubscriptionFlush(sessions, previousHotSessio
5002
5043
  excluded.add(sessionId);
5003
5044
  continue;
5004
5045
  }
5046
+ if (activeSessionIds.has(sessionId)) {
5047
+ active.add(sessionId);
5048
+ continue;
5049
+ }
5005
5050
  const status = String(session?.status || "").toLowerCase();
5006
5051
  const unread = session?.unread === true;
5007
5052
  const inboxBucket = String(session?.inboxBucket || "").toLowerCase();
@@ -15966,6 +16011,9 @@ var ProviderLoader = class _ProviderLoader {
15966
16011
  log(msg) {
15967
16012
  this.logFn(`[ProviderLoader] ${msg}`);
15968
16013
  }
16014
+ debugLog(msg) {
16015
+ LOG.debug("Provider", `[ProviderLoader] ${msg}`);
16016
+ }
15969
16017
  // ─── Public API ────────────────────────────────
15970
16018
  /**
15971
16019
  * User override root (~/.adhdev/providers by default).
@@ -16572,7 +16620,7 @@ var ProviderLoader = class _ProviderLoader {
16572
16620
  const loaded = this.loadScriptsFromDir(type, entry.scriptDir);
16573
16621
  if (loaded) {
16574
16622
  resolved.scripts = loaded;
16575
- this.log(` [compatibility] ${type} v${currentVersion} \u2192 ${entry.scriptDir}`);
16623
+ this.debugLog(` [compatibility] ${type} v${currentVersion} \u2192 ${entry.scriptDir}`);
16576
16624
  resolved._resolvedScriptDir = entry.scriptDir;
16577
16625
  resolved._resolvedScriptsSource = `compatibility:${entry.ideVersion}`;
16578
16626
  if (providerDir) {
@@ -16588,7 +16636,7 @@ var ProviderLoader = class _ProviderLoader {
16588
16636
  const loaded = this.loadScriptsFromDir(type, base.defaultScriptDir);
16589
16637
  if (loaded) {
16590
16638
  resolved.scripts = loaded;
16591
- this.log(` [compatibility] ${type} v${currentVersion} \u2192 default: ${base.defaultScriptDir}`);
16639
+ this.debugLog(` [compatibility] ${type} v${currentVersion} \u2192 default: ${base.defaultScriptDir}`);
16592
16640
  resolved._resolvedScriptDir = base.defaultScriptDir;
16593
16641
  resolved._resolvedScriptsSource = "defaultScriptDir:version_miss";
16594
16642
  if (providerDir) {
@@ -16623,7 +16671,7 @@ var ProviderLoader = class _ProviderLoader {
16623
16671
  const loaded = this.loadScriptsFromDir(type, base.defaultScriptDir);
16624
16672
  if (loaded) {
16625
16673
  resolved.scripts = loaded;
16626
- this.log(` [compatibility] ${type} no version detected \u2192 default: ${base.defaultScriptDir}`);
16674
+ this.debugLog(` [compatibility] ${type} no version detected \u2192 default: ${base.defaultScriptDir}`);
16627
16675
  resolved._resolvedScriptDir = base.defaultScriptDir;
16628
16676
  resolved._resolvedScriptsSource = "defaultScriptDir:no_version";
16629
16677
  if (providerDir) {