@adhdev/daemon-standalone 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.js CHANGED
@@ -39133,9 +39133,9 @@ ${effect.notification.body || ""}`.trim();
39133
39133
  ptyMessageCount: ptyMessages.length,
39134
39134
  returnedMessageCount: returnedMessages.length,
39135
39135
  safeMapping: args.safeMapping === true,
39136
- // true when native-history was selected: PTY message bodies are suppressed and
39137
- // must not be treated as chat content. PTY only contributes status/approval/screen evidence.
39138
- ptyMessagesSuppressed: args.selected === "native-history"
39136
+ // true when PTY message bodies are suppressed and must not be treated as
39137
+ // chat content. PTY may still contribute status/approval/screen evidence.
39138
+ ptyMessagesSuppressed: args.selected === "native-history" || args.ptyStatusApprovalOnly === true
39139
39139
  }
39140
39140
  };
39141
39141
  }
@@ -39151,6 +39151,42 @@ ${effect.notification.body || ""}`.trim();
39151
39151
  if (!args.freshEnough) return "native_history_stale";
39152
39152
  return "native_history_not_selected";
39153
39153
  }
39154
+ function isUnsafeNativeTranscriptFallback(reason) {
39155
+ const value = String(reason || "").trim();
39156
+ return value.startsWith("native_history_unavailable") || value === "native_history_not_safely_mapped" || value === "native_history_stale" || value === "native_history_partial";
39157
+ }
39158
+ function coerceUnsafeNativeFallbackStatus(status, activeModal) {
39159
+ if (status === "waiting_approval" && activeModal) return status;
39160
+ return "idle";
39161
+ }
39162
+ function isRuntimeInputAckMessage(message) {
39163
+ if (!message || typeof message !== "object") return false;
39164
+ const role = String(message.role || "").trim().toLowerCase();
39165
+ if (role !== "user" && role !== "human") return false;
39166
+ const meta3 = message.meta;
39167
+ return !!meta3 && typeof meta3 === "object" && !Array.isArray(meta3) && meta3.runtimeInputAck === true;
39168
+ }
39169
+ function selectRuntimeInputAckMessages(messages) {
39170
+ return messages.filter((message) => isRuntimeInputAckMessage(message));
39171
+ }
39172
+ function readExactRuntimeMirrorMessages(args) {
39173
+ const targetSessionId = String(args.targetSessionId || "").trim();
39174
+ const currentSessionId = String(args.currentSessionId || "").trim();
39175
+ if (!targetSessionId || targetSessionId !== currentSessionId) return [];
39176
+ const history = readChatHistory(
39177
+ args.providerType,
39178
+ 0,
39179
+ Math.max(args.tailLimit || 0, 200),
39180
+ targetSessionId,
39181
+ 0,
39182
+ args.historyBehavior
39183
+ );
39184
+ return normalizeChatMessages(history.messages || []).filter((message) => {
39185
+ const historySessionId = String(message.historySessionId || "").trim();
39186
+ const instanceId = String(message.instanceId || "").trim();
39187
+ return historySessionId === targetSessionId || instanceId === targetSessionId;
39188
+ });
39189
+ }
39154
39190
  function supportsCliNativeTranscript(providerType, provider) {
39155
39191
  if (CLI_NATIVE_TRANSCRIPT_PROVIDERS.has(providerType)) return true;
39156
39192
  return provider?.category === "cli" && isNativeSourceCanonicalHistory(provider?.canonicalHistory);
@@ -39886,6 +39922,7 @@ ${effect.notification.body || ""}`.trim();
39886
39922
  let selectedProviderSessionId = providerSessionId;
39887
39923
  let selectedTranscriptAuthority = transcriptAuthority;
39888
39924
  let selectedCoverage = coverage;
39925
+ let selectedStatus = returnedStatus;
39889
39926
  const sessionWorkspace = typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : typeof adapter.workingDir === "string" ? adapter.workingDir : void 0;
39890
39927
  const intendedWorkspace = typeof args?.workspace === "string" ? args.workspace : void 0;
39891
39928
  let messageSource = buildCliMessageSourceProvenance({
@@ -39997,6 +40034,22 @@ ${effect.notification.body || ""}`.trim();
39997
40034
  safeMapping,
39998
40035
  freshEnough
39999
40036
  });
40037
+ const unsafeNativeFallback = adapter.cliType === "codex-cli" && isUnsafeNativeTranscriptFallback(fallbackReason);
40038
+ const safeRuntimeAckMessages = unsafeNativeFallback ? selectRuntimeInputAckMessages(returnedMessages) : [];
40039
+ const exactRuntimeMirrorMessages = unsafeNativeFallback && safeRuntimeAckMessages.length === 0 ? readExactRuntimeMirrorMessages({
40040
+ providerType,
40041
+ targetSessionId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0,
40042
+ currentSessionId: typeof h.currentSession?.sessionId === "string" ? h.currentSession.sessionId : void 0,
40043
+ tailLimit: nativeHistoryLimit,
40044
+ historyBehavior: provider?.historyBehavior
40045
+ }) : [];
40046
+ const safeDaemonMessages = safeRuntimeAckMessages.length > 0 ? safeRuntimeAckMessages : exactRuntimeMirrorMessages;
40047
+ if (unsafeNativeFallback) {
40048
+ selectedMessages = safeDaemonMessages;
40049
+ selectedTranscriptAuthority = safeDaemonMessages.length > 0 ? "daemon" : void 0;
40050
+ selectedCoverage = safeDaemonMessages.length > 0 ? "tail" : void 0;
40051
+ selectedStatus = coerceUnsafeNativeFallbackStatus(returnedStatus, activeModal);
40052
+ }
40000
40053
  messageSource = buildCliMessageSourceProvenance({
40001
40054
  selected: "pty-parser",
40002
40055
  provider: adapter.cliType,
@@ -40013,18 +40066,22 @@ ${effect.notification.body || ""}`.trim();
40013
40066
  unavailableReason,
40014
40067
  nativeMessages,
40015
40068
  ptyMessages: returnedMessages,
40016
- returnedMessages,
40069
+ returnedMessages: unsafeNativeFallback ? safeDaemonMessages : returnedMessages,
40017
40070
  safeMapping,
40018
40071
  freshEnough,
40019
- ptyStatusApprovalOnly: false
40072
+ ptyStatusApprovalOnly: unsafeNativeFallback
40020
40073
  });
40074
+ if (unsafeNativeFallback && exactRuntimeMirrorMessages.length > 0) {
40075
+ messageSource.selectedDaemonSource = "exact-runtime-mirror";
40076
+ messageSource.transcriptAuthority = "daemon";
40077
+ }
40021
40078
  }
40022
40079
  }
40023
40080
  }
40024
40081
  LOG2.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}`);
40025
40082
  return buildReadChatCommandResult({
40026
40083
  messages: selectedMessages,
40027
- status: returnedStatus,
40084
+ status: selectedStatus,
40028
40085
  activeModal,
40029
40086
  messageSource,
40030
40087
  transcriptProvenance: messageSource,
@@ -40033,10 +40090,10 @@ ${effect.notification.body || ""}`.trim();
40033
40090
  targetSessionId: String(args?.targetSessionId || ""),
40034
40091
  adapterStatus: String(adapterStatus.status || ""),
40035
40092
  parsedStatus: String(parsedRecord.status || ""),
40036
- returnedStatus: String(returnedStatus || ""),
40093
+ returnedStatus: String(selectedStatus || ""),
40037
40094
  selectedMessageSource: messageSource.selected,
40038
40095
  messageSource,
40039
- 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"),
40096
+ 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"),
40040
40097
  parsedMsgCount: parsedRecord.messages.length,
40041
40098
  returnedMsgCount: selectedMessages.length
40042
40099
  },
@@ -40352,14 +40409,14 @@ ${effect.notification.body || ""}`.trim();
40352
40409
  try {
40353
40410
  const hasStructuredParts = input.parts.some((part) => part.type !== "text");
40354
40411
  if (hasStructuredParts) {
40355
- const target = getTargetInstance(h, args);
40356
- if (!target || target.category !== "cli") {
40412
+ const target2 = getTargetInstance(h, args);
40413
+ if (!target2 || target2.category !== "cli") {
40357
40414
  return { success: false, error: `CLI instance not found for ${provider?.type || args?.agentType || "unknown"}` };
40358
40415
  }
40359
40416
  assertProviderSupportsDeclaredInput(provider, input);
40360
40417
  await waitOnceForFreshHermesCliStart(adapter, _log);
40361
- target.onEvent("send_message", { input });
40362
- return _logSendSuccess(`${transport}-instance`, target.type);
40418
+ target2.onEvent("send_message", { input });
40419
+ return _logSendSuccess(`${transport}-instance`, target2.type);
40363
40420
  }
40364
40421
  assertTextOnlyInput(provider, input);
40365
40422
  if (!text) return { success: false, error: "text required for PTY send" };
@@ -40372,6 +40429,10 @@ ${effect.notification.body || ""}`.trim();
40372
40429
  } else {
40373
40430
  await adapter.sendMessage(text);
40374
40431
  }
40432
+ const target = getTargetInstance(h, args);
40433
+ if (target?.category === "cli" && target.type === adapter.cliType && typeof target.recordAcknowledgedUserInput === "function") {
40434
+ target.recordAcknowledgedUserInput(input);
40435
+ }
40375
40436
  return {
40376
40437
  ..._logSendSuccess(`${transport}-adapter`, adapter.cliType),
40377
40438
  ...forceSend ? { forceSent: true } : {}
@@ -43019,6 +43080,26 @@ ${effect.notification.body || ""}`.trim();
43019
43080
  this.applyProviderResponse(data, { phase: "immediate" });
43020
43081
  }
43021
43082
  }
43083
+ recordAcknowledgedUserInput(input) {
43084
+ const content = typeof input === "string" ? input.trim() : buildCliStructuredInputPrompt(input).trim();
43085
+ if (!content) return;
43086
+ const receivedAt = Date.now();
43087
+ const dedupKey = `user_input_ack:${crypto3.createHash("sha256").update(`${this.instanceId}:${content}:${receivedAt}`).digest("hex").slice(0, 24)}`;
43088
+ this.appendRuntimeMessage(buildChatMessage({
43089
+ role: "user",
43090
+ senderName: "User",
43091
+ kind: "standard",
43092
+ content,
43093
+ receivedAt,
43094
+ timestamp: receivedAt,
43095
+ source: "runtime_input_ack",
43096
+ meta: {
43097
+ runtimeInputAck: true,
43098
+ provider: this.type,
43099
+ workspace: this.workingDir
43100
+ }
43101
+ }), dedupKey);
43102
+ }
43022
43103
  dispose() {
43023
43104
  this.adapter.shutdown();
43024
43105
  this.monitor.reset();
@@ -43628,17 +43709,28 @@ ${effect.notification.body || ""}`.trim();
43628
43709
  index,
43629
43710
  source: "parsed"
43630
43711
  }));
43712
+ const getRole = (message) => typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
43631
43713
  const runtimeEntries = this.runtimeMessages.map((entry, index) => ({
43632
43714
  message: entry.message,
43633
43715
  index: parsedMessages.length + index,
43634
43716
  source: "runtime",
43635
43717
  runtimeKey: entry.key
43636
- }));
43718
+ })).filter((entry) => {
43719
+ const meta3 = entry.message.meta && typeof entry.message.meta === "object" && !Array.isArray(entry.message.meta) ? entry.message.meta : {};
43720
+ if (meta3.runtimeInputAck !== true) return true;
43721
+ const runtimeText = flattenContent(entry.message.content).replace(/\s+/g, " ").trim();
43722
+ if (!runtimeText) return false;
43723
+ return !parsedEntries.some((parsedEntry) => {
43724
+ const parsedRole = getRole(parsedEntry.message);
43725
+ if (parsedRole !== "user" && parsedRole !== "human") return false;
43726
+ const parsedText = flattenContent(parsedEntry.message.content).replace(/\s+/g, " ").trim();
43727
+ return parsedText === runtimeText;
43728
+ });
43729
+ });
43637
43730
  const getTime = (message) => {
43638
43731
  const value = typeof message.receivedAt === "number" ? message.receivedAt : typeof message.timestamp === "number" ? message.timestamp : 0;
43639
43732
  return Number.isFinite(value) && value > 0 ? value : 0;
43640
43733
  };
43641
- const getRole = (message) => typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
43642
43734
  const isRuntimeOverlay = (entry) => {
43643
43735
  if (entry.source !== "runtime") return false;
43644
43736
  const key = typeof entry.runtimeKey === "string" ? entry.runtimeKey.trim().toLowerCase() : "";