@adhdev/daemon-core 0.9.82-rc.90 → 0.9.82-rc.92

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
@@ -9423,7 +9423,19 @@ function sessionStatusFromNodes(nodes, nodeId, sessionId) {
9423
9423
  if (!node) return { staleReason: "direct task node is no longer in the live mesh" };
9424
9424
  if (!sessionId) return {};
9425
9425
  const candidates = [];
9426
- for (const value of [node.sessions, node.activeSessions, node.active_sessions, node.lastProbe?.sessions, node.last_probe?.sessions, node.lastProbe?.status?.sessions, node.last_probe?.status?.sessions]) {
9426
+ for (const value of [
9427
+ node.sessions,
9428
+ node.activeSessions,
9429
+ node.active_sessions,
9430
+ node.activeSessionDetails,
9431
+ node.active_session_details,
9432
+ node.sessionDetails,
9433
+ node.session_details,
9434
+ node.lastProbe?.sessions,
9435
+ node.last_probe?.sessions,
9436
+ node.lastProbe?.status?.sessions,
9437
+ node.last_probe?.status?.sessions
9438
+ ]) {
9427
9439
  if (Array.isArray(value)) candidates.push(...value);
9428
9440
  }
9429
9441
  for (const value of [node.activeSession, node.active_session, node.currentSession, node.current_session, node.runtimeSession, node.runtime_session, node.session]) {
@@ -11767,15 +11779,6 @@ function extractFinalSummaryFromMessages(messages, maxChars = DEFAULT_FINAL_SUMM
11767
11779
  if (text) return text.slice(0, maxChars);
11768
11780
  }
11769
11781
  }
11770
- for (let i = messages.length - 1; i >= 0; i--) {
11771
- const msg = messages[i];
11772
- if (!msg) continue;
11773
- const classification = classifyChatMessageVisibility(msg);
11774
- if (classification.isUserFacing) {
11775
- const text = flattenContent(msg.content).trim();
11776
- if (text) return text.slice(0, maxChars);
11777
- }
11778
- }
11779
11782
  return "";
11780
11783
  }
11781
11784
  var BUILTIN_CHAT_MESSAGE_KINDS = ["standard", "thought", "tool", "terminal", "system"];
@@ -15996,6 +15999,13 @@ function getCurrentManagerKey(h) {
15996
15999
  function getTargetedCliAdapter(h, args, providerType) {
15997
16000
  return h.getCliAdapter(args?.targetSessionId || providerType || h.currentSession?.providerType || h.currentManagerKey);
15998
16001
  }
16002
+ function getExplicitHistorySessionId(args) {
16003
+ const explicit = typeof args?.historySessionId === "string" ? args.historySessionId.trim() : "";
16004
+ if (explicit) return explicit;
16005
+ const explicitProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : "";
16006
+ if (explicitProviderSessionId) return explicitProviderSessionId;
16007
+ return void 0;
16008
+ }
15999
16009
  function getTargetInstance(h, args) {
16000
16010
  const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
16001
16011
  const sessionId = targetSessionId || h.currentSession?.sessionId || "";
@@ -16064,13 +16074,14 @@ async function waitOnceForFreshHermesCliStart(adapter, log) {
16064
16074
  await sleep(HERMES_CLI_STARTING_SEND_SETTLE_MS);
16065
16075
  }
16066
16076
  function getHistorySessionId(h, args) {
16067
- const explicit = typeof args?.historySessionId === "string" ? args.historySessionId.trim() : "";
16077
+ const explicit = getExplicitHistorySessionId(args);
16068
16078
  if (explicit) return explicit;
16069
- const explicitProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : "";
16070
- if (explicitProviderSessionId) return explicitProviderSessionId;
16071
16079
  const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
16072
16080
  if (!targetSessionId) return void 0;
16073
- const instance = h.ctx.instanceManager?.getInstance(targetSessionId);
16081
+ const session = h.ctx.sessionRegistry?.get(targetSessionId);
16082
+ const registeredProviderSessionId = typeof session?.providerSessionId === "string" ? session.providerSessionId.trim() : "";
16083
+ if (registeredProviderSessionId) return registeredProviderSessionId;
16084
+ const instance = getTargetInstance(h, args);
16074
16085
  const state = instance?.getState?.();
16075
16086
  const providerSessionId = typeof state?.providerSessionId === "string" ? state.providerSessionId.trim() : "";
16076
16087
  if (providerSessionId) return providerSessionId;
@@ -16081,6 +16092,15 @@ function getHistorySessionId(h, args) {
16081
16092
  }
16082
16093
  return targetSessionId;
16083
16094
  }
16095
+ function resolveCliNativeHistorySessionId(args, currentHistorySessionId, parsedProviderSessionId) {
16096
+ const explicit = getExplicitHistorySessionId(args);
16097
+ if (explicit) return explicit;
16098
+ const parsed = typeof parsedProviderSessionId === "string" ? parsedProviderSessionId.trim() : "";
16099
+ const current = typeof currentHistorySessionId === "string" ? currentHistorySessionId.trim() : "";
16100
+ const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
16101
+ if (parsed && (!current || current === targetSessionId)) return parsed;
16102
+ return current || parsed || void 0;
16103
+ }
16084
16104
  function getInteractionId(args) {
16085
16105
  return typeof args?._interactionId === "string" && args._interactionId.trim() ? args._interactionId.trim() : void 0;
16086
16106
  }
@@ -16225,6 +16245,29 @@ function supportsCliNativeTranscript(providerType, provider) {
16225
16245
  if (CLI_NATIVE_TRANSCRIPT_PROVIDERS.has(providerType)) return true;
16226
16246
  return provider?.category === "cli" && isNativeSourceCanonicalHistory(provider?.canonicalHistory);
16227
16247
  }
16248
+ function getComparableVisibleText(message) {
16249
+ if (!message) return "";
16250
+ const role = String(message.role || "").trim().toLowerCase();
16251
+ if (role !== "user" && role !== "assistant") return "";
16252
+ const kind = String(message.kind || "standard").trim().toLowerCase();
16253
+ if (kind && kind !== "standard") return "";
16254
+ const content = flattenContent(message.content).replace(/\s+/g, " ").trim();
16255
+ return content;
16256
+ }
16257
+ function hasOverlappingVisibleConversationText(nativeMessages, ptyMessages) {
16258
+ const nativeTexts = nativeMessages.map(getComparableVisibleText).filter(Boolean);
16259
+ const ptyTexts = ptyMessages.map(getComparableVisibleText).filter(Boolean);
16260
+ if (nativeTexts.length === 0 || ptyTexts.length === 0) return false;
16261
+ for (const nativeText of nativeTexts) {
16262
+ for (const ptyText of ptyTexts) {
16263
+ if (nativeText === ptyText) return true;
16264
+ const shorter = nativeText.length <= ptyText.length ? nativeText : ptyText;
16265
+ const longer = nativeText.length <= ptyText.length ? ptyText : nativeText;
16266
+ if (shorter.length >= 32 && longer.includes(shorter)) return true;
16267
+ }
16268
+ }
16269
+ return false;
16270
+ }
16228
16271
  function hasSafeNativeHistoryMapping(args) {
16229
16272
  const explicitSessionId = String(args.historySessionId || args.providerSessionId || "").trim();
16230
16273
  if (explicitSessionId) {
@@ -16234,7 +16277,10 @@ function hasSafeNativeHistoryMapping(args) {
16234
16277
  }
16235
16278
  const workspace = String(args.workspace || "").trim();
16236
16279
  if (!workspace) return false;
16237
- return args.nativeMessages.some((message) => String(message?.workspace || "").trim() === workspace);
16280
+ const workspaceMatches = args.nativeMessages.some((message) => String(message?.workspace || "").trim() === workspace);
16281
+ if (!workspaceMatches) return false;
16282
+ if (!args.requireWorkspaceContentOverlap) return true;
16283
+ return hasOverlappingVisibleConversationText(args.nativeMessages, args.ptyMessages || []);
16238
16284
  }
16239
16285
  function readCliProviderNativeHistory(agentStr, args) {
16240
16286
  const sessionHistory = readProviderChatHistory(agentStr, {
@@ -16247,8 +16293,8 @@ function readCliProviderNativeHistory(agentStr, args) {
16247
16293
  historyBehavior: args.historyBehavior,
16248
16294
  scripts: args.scripts
16249
16295
  });
16250
- if (sessionHistory.source !== "native-unavailable" || !args.historySessionId || !args.workspace) {
16251
- return { ...sessionHistory, lookup: "session" };
16296
+ if (sessionHistory.source !== "native-unavailable" || args.exactSessionScoped || !args.historySessionId || !args.workspace) {
16297
+ return { ...sessionHistory, lookup: args.historySessionId ? "session" : "workspace" };
16252
16298
  }
16253
16299
  const workspaceHistory = readProviderChatHistory(agentStr, {
16254
16300
  canonicalHistory: args.canonicalHistory,
@@ -16273,6 +16319,19 @@ function isNativeHistoryFreshEnough(args) {
16273
16319
  function shouldPreserveReadChatPayloadField(key) {
16274
16320
  return key === "messageSource" || key === "transcriptProvenance";
16275
16321
  }
16322
+ function updateMessageSourceReturnedCount(value, returnedMessageCount) {
16323
+ if (!value || typeof value !== "object" || Array.isArray(value)) return value;
16324
+ const record = value;
16325
+ const coverage = record.coverage && typeof record.coverage === "object" && !Array.isArray(record.coverage) ? record.coverage : void 0;
16326
+ if (!coverage) return value;
16327
+ return {
16328
+ ...record,
16329
+ coverage: {
16330
+ ...coverage,
16331
+ returnedMessageCount
16332
+ }
16333
+ };
16334
+ }
16276
16335
  function deriveHistoryDedupKey(message) {
16277
16336
  const unitKey = typeof message._unitKey === "string" ? message._unitKey.trim() : "";
16278
16337
  if (unitKey) return `read_chat:${unitKey}`;
@@ -16384,6 +16443,13 @@ function buildReadChatCommandResult(payload, args) {
16384
16443
  const visibleMessages = filterUserFacingChatMessages(messages);
16385
16444
  const sync = buildFullTail(visibleMessages, normalizeReadChatTailLimit(args));
16386
16445
  const hiddenMsgCount = Math.max(0, messages.length - visibleMessages.length);
16446
+ const preservedPayloadFields = Object.fromEntries(Object.entries(payload).filter(([key]) => shouldPreserveReadChatPayloadField(key)));
16447
+ if (preservedPayloadFields.messageSource) {
16448
+ preservedPayloadFields.messageSource = updateMessageSourceReturnedCount(preservedPayloadFields.messageSource, sync.messages.length);
16449
+ }
16450
+ if (preservedPayloadFields.transcriptProvenance) {
16451
+ preservedPayloadFields.transcriptProvenance = updateMessageSourceReturnedCount(preservedPayloadFields.transcriptProvenance, sync.messages.length);
16452
+ }
16387
16453
  const returnedDebugReadChat = debugReadChat ? {
16388
16454
  ...debugReadChat,
16389
16455
  fullMsgCount: typeof debugReadChat.fullMsgCount === "number" ? debugReadChat.fullMsgCount : messages.length,
@@ -16394,7 +16460,7 @@ function buildReadChatCommandResult(payload, args) {
16394
16460
  return {
16395
16461
  success: true,
16396
16462
  ...validatedPayload,
16397
- ...Object.fromEntries(Object.entries(payload).filter(([key]) => shouldPreserveReadChatPayloadField(key))),
16463
+ ...preservedPayloadFields,
16398
16464
  messages: sync.messages,
16399
16465
  totalMessages: sync.totalMessages,
16400
16466
  ...returnedDebugReadChat ? { debugReadChat: returnedDebugReadChat } : {}
@@ -16869,17 +16935,23 @@ async function handleReadChat(h, args) {
16869
16935
  returnedMessages.length,
16870
16936
  200
16871
16937
  );
16938
+ const nativeHistorySessionId = resolveCliNativeHistorySessionId(args, historySessionId, providerSessionId);
16939
+ const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
16940
+ const exactNativeHistoryScope = Boolean(
16941
+ typeof args?.historySessionId === "string" && args.historySessionId.trim() || typeof args?.providerSessionId === "string" && args.providerSessionId.trim() || providerSessionId || nativeHistorySessionId && nativeHistorySessionId !== targetSessionId || h.currentSession?.sessionId === args?.targetSessionId && typeof h.currentSession?.providerSessionId === "string" && h.currentSession.providerSessionId.trim()
16942
+ );
16872
16943
  let nativeHistory = null;
16873
16944
  try {
16874
16945
  nativeHistory = readCliProviderNativeHistory(agentStr, {
16875
16946
  canonicalHistory: provider?.canonicalHistory,
16876
- historySessionId,
16947
+ historySessionId: nativeHistorySessionId,
16877
16948
  workspace,
16878
16949
  offset: 0,
16879
16950
  limit: nativeHistoryLimit,
16880
16951
  excludeRecentCount: 0,
16881
16952
  historyBehavior: provider?.historyBehavior,
16882
- scripts: provider?.scripts
16953
+ scripts: provider?.scripts,
16954
+ exactSessionScoped: exactNativeHistoryScope
16883
16955
  });
16884
16956
  } catch (error) {
16885
16957
  const fallbackReason = `native_history_error:${error?.message || String(error)}`;
@@ -16895,13 +16967,15 @@ async function handleReadChat(h, args) {
16895
16967
  }
16896
16968
  if (nativeHistory) {
16897
16969
  const nativeMessages = Array.isArray(nativeHistory.messages) ? normalizeNativeHistoryMessages(agentStr, nativeHistory.messages) : [];
16898
- const historyProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId : readHistorySessionIdFromMessages(nativeMessages) || historySessionId;
16970
+ const historyProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId : readHistorySessionIdFromMessages(nativeMessages) || nativeHistorySessionId || historySessionId;
16899
16971
  const lookup = nativeHistory.lookup === "workspace" ? "workspace" : "session";
16900
16972
  const safeMapping = hasSafeNativeHistoryMapping({
16901
- historySessionId: lookup === "workspace" ? void 0 : historySessionId,
16902
- providerSessionId: lookup === "workspace" ? void 0 : providerSessionId,
16973
+ historySessionId: lookup === "workspace" ? void 0 : nativeHistorySessionId,
16974
+ providerSessionId: lookup === "workspace" ? void 0 : historyProviderSessionId || providerSessionId,
16903
16975
  workspace,
16904
- nativeMessages
16976
+ nativeMessages,
16977
+ ptyMessages: returnedMessages,
16978
+ requireWorkspaceContentOverlap: lookup === "workspace" && !exactNativeHistoryScope
16905
16979
  });
16906
16980
  const freshEnough = isNativeHistoryFreshEnough({
16907
16981
  sourceMtimeMs: nativeHistory.sourceMtimeMs,
@@ -16916,7 +16990,7 @@ async function handleReadChat(h, args) {
16916
16990
  messageSource = buildCliMessageSourceProvenance({
16917
16991
  selected: "native-history",
16918
16992
  provider: adapter.cliType,
16919
- nativeHandle: selectedProviderSessionId || historySessionId,
16993
+ nativeHandle: selectedProviderSessionId || nativeHistorySessionId || historySessionId,
16920
16994
  nativeSource: nativeHistory.source,
16921
16995
  sourcePath: nativeHistory.sourcePath,
16922
16996
  sourceMtimeMs: nativeHistory.sourceMtimeMs,
@@ -16939,7 +17013,7 @@ async function handleReadChat(h, args) {
16939
17013
  messageSource = buildCliMessageSourceProvenance({
16940
17014
  selected: "pty-parser",
16941
17015
  provider: adapter.cliType,
16942
- nativeHandle: historyProviderSessionId || historySessionId,
17016
+ nativeHandle: historyProviderSessionId || nativeHistorySessionId || historySessionId,
16943
17017
  fallbackReason,
16944
17018
  nativeSource: nativeHistory.source,
16945
17019
  sourcePath: nativeHistory.sourcePath,
@@ -16983,6 +17057,9 @@ async function handleReadChat(h, args) {
16983
17057
  try {
16984
17058
  const agentStr = provider?.type || args?.agentType || getCurrentProviderType(h);
16985
17059
  const workspace = typeof args?.workspace === "string" ? args.workspace : typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : void 0;
17060
+ const exactNativeHistoryScope = Boolean(
17061
+ typeof args?.historySessionId === "string" && args.historySessionId.trim() || typeof args?.providerSessionId === "string" && args.providerSessionId.trim() || h.currentSession?.sessionId === args?.targetSessionId && typeof h.currentSession?.providerSessionId === "string" && h.currentSession.providerSessionId.trim()
17062
+ );
16986
17063
  const history = supportsCliNativeTranscript(agentStr, provider) && isNativeSourceCanonicalHistory(provider?.canonicalHistory) ? readCliProviderNativeHistory(agentStr, {
16987
17064
  canonicalHistory: provider?.canonicalHistory,
16988
17065
  historySessionId,
@@ -16991,7 +17068,8 @@ async function handleReadChat(h, args) {
16991
17068
  limit: historyLimit,
16992
17069
  excludeRecentCount: 0,
16993
17070
  historyBehavior: provider?.historyBehavior,
16994
- scripts: provider?.scripts
17071
+ scripts: provider?.scripts,
17072
+ exactSessionScoped: exactNativeHistoryScope
16995
17073
  }) : readProviderChatHistory(agentStr, {
16996
17074
  canonicalHistory: provider?.canonicalHistory,
16997
17075
  historySessionId,
@@ -19754,6 +19832,7 @@ var CliProviderInstance = class {
19754
19832
  }
19755
19833
  const runtime = this.adapter.getRuntimeMetadata();
19756
19834
  this.maybeAppendRuntimeRecoveryMessage(runtime);
19835
+ const activeChatId = this.providerSessionId || runtime?.runtimeId || this.instanceId;
19757
19836
  let parsedMessages = Array.isArray(parsedStatus?.messages) ? parsedStatus.messages : [];
19758
19837
  const historyMessageCount = Number.isFinite(parsedStatus?.historyMessageCount) ? Math.max(0, Number(parsedStatus.historyMessageCount)) : null;
19759
19838
  if (historyMessageCount !== null) {
@@ -19809,7 +19888,7 @@ var CliProviderInstance = class {
19809
19888
  status: visibleStatus,
19810
19889
  mode: this.presentationMode,
19811
19890
  activeChat: {
19812
- id: `${this.type}_${this.workingDir}`,
19891
+ id: activeChatId,
19813
19892
  title: parsedStatus?.title || dirName,
19814
19893
  status: activeChatStatus,
19815
19894
  messages: mergedMessages,