@adhdev/daemon-core 0.9.82-rc.127 → 0.9.82-rc.129

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
@@ -16841,9 +16841,9 @@ function buildCliMessageSourceProvenance(args) {
16841
16841
  ptyMessageCount: ptyMessages.length,
16842
16842
  returnedMessageCount: returnedMessages.length,
16843
16843
  safeMapping: args.safeMapping === true,
16844
- // true when native-history was selected: PTY message bodies are suppressed and
16845
- // must not be treated as chat content. PTY only contributes status/approval/screen evidence.
16846
- ptyMessagesSuppressed: args.selected === "native-history"
16844
+ // true when PTY message bodies are suppressed and must not be treated as
16845
+ // chat content. PTY may still contribute status/approval/screen evidence.
16846
+ ptyMessagesSuppressed: args.selected === "native-history" || args.ptyStatusApprovalOnly === true
16847
16847
  }
16848
16848
  };
16849
16849
  }
@@ -16859,6 +16859,42 @@ function buildNativeHistoryFallbackReason(args) {
16859
16859
  if (!args.freshEnough) return "native_history_stale";
16860
16860
  return "native_history_not_selected";
16861
16861
  }
16862
+ function isUnsafeNativeTranscriptFallback(reason) {
16863
+ const value = String(reason || "").trim();
16864
+ return value.startsWith("native_history_unavailable") || value === "native_history_not_safely_mapped" || value === "native_history_stale" || value === "native_history_partial";
16865
+ }
16866
+ function coerceUnsafeNativeFallbackStatus(status, activeModal) {
16867
+ if (status === "waiting_approval" && activeModal) return status;
16868
+ return "idle";
16869
+ }
16870
+ function isRuntimeInputAckMessage(message) {
16871
+ if (!message || typeof message !== "object") return false;
16872
+ const role = String(message.role || "").trim().toLowerCase();
16873
+ if (role !== "user" && role !== "human") return false;
16874
+ const meta = message.meta;
16875
+ return !!meta && typeof meta === "object" && !Array.isArray(meta) && meta.runtimeInputAck === true;
16876
+ }
16877
+ function selectRuntimeInputAckMessages(messages) {
16878
+ return messages.filter((message) => isRuntimeInputAckMessage(message));
16879
+ }
16880
+ function readExactRuntimeMirrorMessages(args) {
16881
+ const targetSessionId = String(args.targetSessionId || "").trim();
16882
+ const currentSessionId = String(args.currentSessionId || "").trim();
16883
+ if (!targetSessionId || targetSessionId !== currentSessionId) return [];
16884
+ const history = readChatHistory(
16885
+ args.providerType,
16886
+ 0,
16887
+ Math.max(args.tailLimit || 0, 200),
16888
+ targetSessionId,
16889
+ 0,
16890
+ args.historyBehavior
16891
+ );
16892
+ return normalizeChatMessages(history.messages || []).filter((message) => {
16893
+ const historySessionId = String(message.historySessionId || "").trim();
16894
+ const instanceId = String(message.instanceId || "").trim();
16895
+ return historySessionId === targetSessionId || instanceId === targetSessionId;
16896
+ });
16897
+ }
16862
16898
  function supportsCliNativeTranscript(providerType, provider) {
16863
16899
  if (CLI_NATIVE_TRANSCRIPT_PROVIDERS.has(providerType)) return true;
16864
16900
  return provider?.category === "cli" && isNativeSourceCanonicalHistory(provider?.canonicalHistory);
@@ -17594,6 +17630,7 @@ async function handleReadChat(h, args) {
17594
17630
  let selectedProviderSessionId = providerSessionId;
17595
17631
  let selectedTranscriptAuthority = transcriptAuthority;
17596
17632
  let selectedCoverage = coverage;
17633
+ let selectedStatus = returnedStatus;
17597
17634
  const sessionWorkspace = typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : typeof adapter.workingDir === "string" ? adapter.workingDir : void 0;
17598
17635
  const intendedWorkspace = typeof args?.workspace === "string" ? args.workspace : void 0;
17599
17636
  let messageSource = buildCliMessageSourceProvenance({
@@ -17705,6 +17742,22 @@ async function handleReadChat(h, args) {
17705
17742
  safeMapping,
17706
17743
  freshEnough
17707
17744
  });
17745
+ const unsafeNativeFallback = adapter.cliType === "codex-cli" && isUnsafeNativeTranscriptFallback(fallbackReason);
17746
+ const safeRuntimeAckMessages = unsafeNativeFallback ? selectRuntimeInputAckMessages(returnedMessages) : [];
17747
+ const exactRuntimeMirrorMessages = unsafeNativeFallback && safeRuntimeAckMessages.length === 0 ? readExactRuntimeMirrorMessages({
17748
+ providerType,
17749
+ targetSessionId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0,
17750
+ currentSessionId: typeof h.currentSession?.sessionId === "string" ? h.currentSession.sessionId : void 0,
17751
+ tailLimit: nativeHistoryLimit,
17752
+ historyBehavior: provider?.historyBehavior
17753
+ }) : [];
17754
+ const safeDaemonMessages = safeRuntimeAckMessages.length > 0 ? safeRuntimeAckMessages : exactRuntimeMirrorMessages;
17755
+ if (unsafeNativeFallback) {
17756
+ selectedMessages = safeDaemonMessages;
17757
+ selectedTranscriptAuthority = safeDaemonMessages.length > 0 ? "daemon" : void 0;
17758
+ selectedCoverage = safeDaemonMessages.length > 0 ? "tail" : void 0;
17759
+ selectedStatus = coerceUnsafeNativeFallbackStatus(returnedStatus, activeModal);
17760
+ }
17708
17761
  messageSource = buildCliMessageSourceProvenance({
17709
17762
  selected: "pty-parser",
17710
17763
  provider: adapter.cliType,
@@ -17721,18 +17774,22 @@ async function handleReadChat(h, args) {
17721
17774
  unavailableReason,
17722
17775
  nativeMessages,
17723
17776
  ptyMessages: returnedMessages,
17724
- returnedMessages,
17777
+ returnedMessages: unsafeNativeFallback ? safeDaemonMessages : returnedMessages,
17725
17778
  safeMapping,
17726
17779
  freshEnough,
17727
- ptyStatusApprovalOnly: false
17780
+ ptyStatusApprovalOnly: unsafeNativeFallback
17728
17781
  });
17782
+ if (unsafeNativeFallback && exactRuntimeMirrorMessages.length > 0) {
17783
+ messageSource.selectedDaemonSource = "exact-runtime-mirror";
17784
+ messageSource.transcriptAuthority = "daemon";
17785
+ }
17729
17786
  }
17730
17787
  }
17731
17788
  }
17732
17789
  LOG.debug("Command", `[read_chat] cli-like parsed provider=${adapter.cliType} target=${String(args?.targetSessionId || "")} adapterStatus=${String(adapterStatus.status || "")} parsedStatus=${String(parsedRecord.status || "")} parsedMsgCount=${parsedRecord.messages.length} returnedMsgCount=${returnedMessages.length}`);
17733
17790
  return buildReadChatCommandResult({
17734
17791
  messages: selectedMessages,
17735
- status: returnedStatus,
17792
+ status: selectedStatus,
17736
17793
  activeModal,
17737
17794
  messageSource,
17738
17795
  transcriptProvenance: messageSource,
@@ -17741,10 +17798,10 @@ async function handleReadChat(h, args) {
17741
17798
  targetSessionId: String(args?.targetSessionId || ""),
17742
17799
  adapterStatus: String(adapterStatus.status || ""),
17743
17800
  parsedStatus: String(parsedRecord.status || ""),
17744
- returnedStatus: String(returnedStatus || ""),
17801
+ returnedStatus: String(selectedStatus || ""),
17745
17802
  selectedMessageSource: messageSource.selected,
17746
17803
  messageSource,
17747
- shouldPreferAdapterMessages: supportsCliNativeTranscript(providerType, provider) && isNativeSourceCanonicalHistory(provider?.canonicalHistory) && messageSource.selected !== "native-history" && typeof messageSource.fallbackReason === "string" && messageSource.fallbackReason.startsWith("native_history_") && messageSource.fallbackReason !== "native_history_not_checked" && !(selectedTranscriptAuthority === "provider" && selectedCoverage === "full"),
17804
+ shouldPreferAdapterMessages: supportsCliNativeTranscript(providerType, provider) && isNativeSourceCanonicalHistory(provider?.canonicalHistory) && messageSource.selected !== "native-history" && typeof messageSource.fallbackReason === "string" && messageSource.fallbackReason.startsWith("native_history_") && messageSource.fallbackReason !== "native_history_not_checked" && !isUnsafeNativeTranscriptFallback(messageSource.fallbackReason) && !(selectedTranscriptAuthority === "provider" && selectedCoverage === "full"),
17748
17805
  parsedMsgCount: parsedRecord.messages.length,
17749
17806
  returnedMsgCount: selectedMessages.length
17750
17807
  },
@@ -18060,14 +18117,14 @@ async function handleSendChat(h, args) {
18060
18117
  try {
18061
18118
  const hasStructuredParts = input.parts.some((part) => part.type !== "text");
18062
18119
  if (hasStructuredParts) {
18063
- const target = getTargetInstance(h, args);
18064
- if (!target || target.category !== "cli") {
18120
+ const target2 = getTargetInstance(h, args);
18121
+ if (!target2 || target2.category !== "cli") {
18065
18122
  return { success: false, error: `CLI instance not found for ${provider?.type || args?.agentType || "unknown"}` };
18066
18123
  }
18067
18124
  assertProviderSupportsDeclaredInput(provider, input);
18068
18125
  await waitOnceForFreshHermesCliStart(adapter, _log);
18069
- target.onEvent("send_message", { input });
18070
- return _logSendSuccess(`${transport}-instance`, target.type);
18126
+ target2.onEvent("send_message", { input });
18127
+ return _logSendSuccess(`${transport}-instance`, target2.type);
18071
18128
  }
18072
18129
  assertTextOnlyInput(provider, input);
18073
18130
  if (!text) return { success: false, error: "text required for PTY send" };
@@ -18080,6 +18137,10 @@ async function handleSendChat(h, args) {
18080
18137
  } else {
18081
18138
  await adapter.sendMessage(text);
18082
18139
  }
18140
+ const target = getTargetInstance(h, args);
18141
+ if (target?.category === "cli" && target.type === adapter.cliType && typeof target.recordAcknowledgedUserInput === "function") {
18142
+ target.recordAcknowledgedUserInput(input);
18143
+ }
18083
18144
  return {
18084
18145
  ..._logSendSuccess(`${transport}-adapter`, adapter.cliType),
18085
18146
  ...forceSend ? { forceSent: true } : {}
@@ -20749,6 +20810,26 @@ var CliProviderInstance = class {
20749
20810
  this.applyProviderResponse(data, { phase: "immediate" });
20750
20811
  }
20751
20812
  }
20813
+ recordAcknowledgedUserInput(input) {
20814
+ const content = typeof input === "string" ? input.trim() : buildCliStructuredInputPrompt(input).trim();
20815
+ if (!content) return;
20816
+ const receivedAt = Date.now();
20817
+ const dedupKey = `user_input_ack:${crypto3.createHash("sha256").update(`${this.instanceId}:${content}:${receivedAt}`).digest("hex").slice(0, 24)}`;
20818
+ this.appendRuntimeMessage(buildChatMessage({
20819
+ role: "user",
20820
+ senderName: "User",
20821
+ kind: "standard",
20822
+ content,
20823
+ receivedAt,
20824
+ timestamp: receivedAt,
20825
+ source: "runtime_input_ack",
20826
+ meta: {
20827
+ runtimeInputAck: true,
20828
+ provider: this.type,
20829
+ workspace: this.workingDir
20830
+ }
20831
+ }), dedupKey);
20832
+ }
20752
20833
  dispose() {
20753
20834
  this.adapter.shutdown();
20754
20835
  this.monitor.reset();
@@ -21358,17 +21439,28 @@ ${effect.notification.body || ""}`.trim();
21358
21439
  index,
21359
21440
  source: "parsed"
21360
21441
  }));
21442
+ const getRole = (message) => typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
21361
21443
  const runtimeEntries = this.runtimeMessages.map((entry, index) => ({
21362
21444
  message: entry.message,
21363
21445
  index: parsedMessages.length + index,
21364
21446
  source: "runtime",
21365
21447
  runtimeKey: entry.key
21366
- }));
21448
+ })).filter((entry) => {
21449
+ const meta = entry.message.meta && typeof entry.message.meta === "object" && !Array.isArray(entry.message.meta) ? entry.message.meta : {};
21450
+ if (meta.runtimeInputAck !== true) return true;
21451
+ const runtimeText = flattenContent(entry.message.content).replace(/\s+/g, " ").trim();
21452
+ if (!runtimeText) return false;
21453
+ return !parsedEntries.some((parsedEntry) => {
21454
+ const parsedRole = getRole(parsedEntry.message);
21455
+ if (parsedRole !== "user" && parsedRole !== "human") return false;
21456
+ const parsedText = flattenContent(parsedEntry.message.content).replace(/\s+/g, " ").trim();
21457
+ return parsedText === runtimeText;
21458
+ });
21459
+ });
21367
21460
  const getTime = (message) => {
21368
21461
  const value = typeof message.receivedAt === "number" ? message.receivedAt : typeof message.timestamp === "number" ? message.timestamp : 0;
21369
21462
  return Number.isFinite(value) && value > 0 ? value : 0;
21370
21463
  };
21371
- const getRole = (message) => typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
21372
21464
  const isRuntimeOverlay = (entry) => {
21373
21465
  if (entry.source !== "runtime") return false;
21374
21466
  const key = typeof entry.runtimeKey === "string" ? entry.runtimeKey.trim().toLowerCase() : "";
@@ -26229,7 +26321,7 @@ init_logger();
26229
26321
  import * as yaml3 from "js-yaml";
26230
26322
 
26231
26323
  // src/commands/mesh-coordinator.ts
26232
- import { createHash as createHash3 } from "crypto";
26324
+ import { createHash as createHash4 } from "crypto";
26233
26325
  import * as os17 from "os";
26234
26326
  import { isAbsolute as isAbsolute11, join as join23, resolve as resolve13 } from "path";
26235
26327
  var DEFAULT_SERVER_NAME = "adhdev-mesh";
@@ -26372,7 +26464,7 @@ function renderMeshCoordinatorTemplate(template, values) {
26372
26464
  function resolveHermesCoordinatorHome(meshId, workspace) {
26373
26465
  const key = `${meshId || "mesh"}
26374
26466
  ${resolve13(workspace || os17.tmpdir())}`;
26375
- const hash = createHash3("sha256").update(key).digest("hex").slice(0, 16);
26467
+ const hash = createHash4("sha256").update(key).digest("hex").slice(0, 16);
26376
26468
  return join23(os17.tmpdir(), `adhdev-hermes-mesh-coordinator-${hash}`);
26377
26469
  }
26378
26470
  function resolveMcpConfigPath(configPath, workspace) {