@adhdev/daemon-core 0.9.82-rc.128 → 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
@@ -17133,6 +17133,34 @@ function coerceUnsafeNativeFallbackStatus(status, activeModal) {
17133
17133
  if (status === "waiting_approval" && activeModal) return status;
17134
17134
  return "idle";
17135
17135
  }
17136
+ function isRuntimeInputAckMessage(message) {
17137
+ if (!message || typeof message !== "object") return false;
17138
+ const role = String(message.role || "").trim().toLowerCase();
17139
+ if (role !== "user" && role !== "human") return false;
17140
+ const meta = message.meta;
17141
+ return !!meta && typeof meta === "object" && !Array.isArray(meta) && meta.runtimeInputAck === true;
17142
+ }
17143
+ function selectRuntimeInputAckMessages(messages) {
17144
+ return messages.filter((message) => isRuntimeInputAckMessage(message));
17145
+ }
17146
+ function readExactRuntimeMirrorMessages(args) {
17147
+ const targetSessionId = String(args.targetSessionId || "").trim();
17148
+ const currentSessionId = String(args.currentSessionId || "").trim();
17149
+ if (!targetSessionId || targetSessionId !== currentSessionId) return [];
17150
+ const history = readChatHistory(
17151
+ args.providerType,
17152
+ 0,
17153
+ Math.max(args.tailLimit || 0, 200),
17154
+ targetSessionId,
17155
+ 0,
17156
+ args.historyBehavior
17157
+ );
17158
+ return normalizeChatMessages(history.messages || []).filter((message) => {
17159
+ const historySessionId = String(message.historySessionId || "").trim();
17160
+ const instanceId = String(message.instanceId || "").trim();
17161
+ return historySessionId === targetSessionId || instanceId === targetSessionId;
17162
+ });
17163
+ }
17136
17164
  function supportsCliNativeTranscript(providerType, provider) {
17137
17165
  if (CLI_NATIVE_TRANSCRIPT_PROVIDERS.has(providerType)) return true;
17138
17166
  return provider?.category === "cli" && isNativeSourceCanonicalHistory(provider?.canonicalHistory);
@@ -17981,10 +18009,19 @@ async function handleReadChat(h, args) {
17981
18009
  freshEnough
17982
18010
  });
17983
18011
  const unsafeNativeFallback = adapter.cliType === "codex-cli" && isUnsafeNativeTranscriptFallback(fallbackReason);
18012
+ const safeRuntimeAckMessages = unsafeNativeFallback ? selectRuntimeInputAckMessages(returnedMessages) : [];
18013
+ const exactRuntimeMirrorMessages = unsafeNativeFallback && safeRuntimeAckMessages.length === 0 ? readExactRuntimeMirrorMessages({
18014
+ providerType,
18015
+ targetSessionId: typeof args?.targetSessionId === "string" ? args.targetSessionId : void 0,
18016
+ currentSessionId: typeof h.currentSession?.sessionId === "string" ? h.currentSession.sessionId : void 0,
18017
+ tailLimit: nativeHistoryLimit,
18018
+ historyBehavior: provider?.historyBehavior
18019
+ }) : [];
18020
+ const safeDaemonMessages = safeRuntimeAckMessages.length > 0 ? safeRuntimeAckMessages : exactRuntimeMirrorMessages;
17984
18021
  if (unsafeNativeFallback) {
17985
- selectedMessages = [];
17986
- selectedTranscriptAuthority = void 0;
17987
- selectedCoverage = void 0;
18022
+ selectedMessages = safeDaemonMessages;
18023
+ selectedTranscriptAuthority = safeDaemonMessages.length > 0 ? "daemon" : void 0;
18024
+ selectedCoverage = safeDaemonMessages.length > 0 ? "tail" : void 0;
17988
18025
  selectedStatus = coerceUnsafeNativeFallbackStatus(returnedStatus, activeModal);
17989
18026
  }
17990
18027
  messageSource = buildCliMessageSourceProvenance({
@@ -18003,11 +18040,15 @@ async function handleReadChat(h, args) {
18003
18040
  unavailableReason,
18004
18041
  nativeMessages,
18005
18042
  ptyMessages: returnedMessages,
18006
- returnedMessages: unsafeNativeFallback ? [] : returnedMessages,
18043
+ returnedMessages: unsafeNativeFallback ? safeDaemonMessages : returnedMessages,
18007
18044
  safeMapping,
18008
18045
  freshEnough,
18009
18046
  ptyStatusApprovalOnly: unsafeNativeFallback
18010
18047
  });
18048
+ if (unsafeNativeFallback && exactRuntimeMirrorMessages.length > 0) {
18049
+ messageSource.selectedDaemonSource = "exact-runtime-mirror";
18050
+ messageSource.transcriptAuthority = "daemon";
18051
+ }
18011
18052
  }
18012
18053
  }
18013
18054
  }
@@ -18342,14 +18383,14 @@ async function handleSendChat(h, args) {
18342
18383
  try {
18343
18384
  const hasStructuredParts = input.parts.some((part) => part.type !== "text");
18344
18385
  if (hasStructuredParts) {
18345
- const target = getTargetInstance(h, args);
18346
- if (!target || target.category !== "cli") {
18386
+ const target2 = getTargetInstance(h, args);
18387
+ if (!target2 || target2.category !== "cli") {
18347
18388
  return { success: false, error: `CLI instance not found for ${provider?.type || args?.agentType || "unknown"}` };
18348
18389
  }
18349
18390
  assertProviderSupportsDeclaredInput(provider, input);
18350
18391
  await waitOnceForFreshHermesCliStart(adapter, _log);
18351
- target.onEvent("send_message", { input });
18352
- return _logSendSuccess(`${transport}-instance`, target.type);
18392
+ target2.onEvent("send_message", { input });
18393
+ return _logSendSuccess(`${transport}-instance`, target2.type);
18353
18394
  }
18354
18395
  assertTextOnlyInput(provider, input);
18355
18396
  if (!text) return { success: false, error: "text required for PTY send" };
@@ -18362,6 +18403,10 @@ async function handleSendChat(h, args) {
18362
18403
  } else {
18363
18404
  await adapter.sendMessage(text);
18364
18405
  }
18406
+ const target = getTargetInstance(h, args);
18407
+ if (target?.category === "cli" && target.type === adapter.cliType && typeof target.recordAcknowledgedUserInput === "function") {
18408
+ target.recordAcknowledgedUserInput(input);
18409
+ }
18365
18410
  return {
18366
18411
  ..._logSendSuccess(`${transport}-adapter`, adapter.cliType),
18367
18412
  ...forceSend ? { forceSent: true } : {}
@@ -21031,6 +21076,26 @@ var CliProviderInstance = class {
21031
21076
  this.applyProviderResponse(data, { phase: "immediate" });
21032
21077
  }
21033
21078
  }
21079
+ recordAcknowledgedUserInput(input) {
21080
+ const content = typeof input === "string" ? input.trim() : buildCliStructuredInputPrompt(input).trim();
21081
+ if (!content) return;
21082
+ const receivedAt = Date.now();
21083
+ const dedupKey = `user_input_ack:${crypto3.createHash("sha256").update(`${this.instanceId}:${content}:${receivedAt}`).digest("hex").slice(0, 24)}`;
21084
+ this.appendRuntimeMessage(buildChatMessage({
21085
+ role: "user",
21086
+ senderName: "User",
21087
+ kind: "standard",
21088
+ content,
21089
+ receivedAt,
21090
+ timestamp: receivedAt,
21091
+ source: "runtime_input_ack",
21092
+ meta: {
21093
+ runtimeInputAck: true,
21094
+ provider: this.type,
21095
+ workspace: this.workingDir
21096
+ }
21097
+ }), dedupKey);
21098
+ }
21034
21099
  dispose() {
21035
21100
  this.adapter.shutdown();
21036
21101
  this.monitor.reset();
@@ -21640,17 +21705,28 @@ ${effect.notification.body || ""}`.trim();
21640
21705
  index,
21641
21706
  source: "parsed"
21642
21707
  }));
21708
+ const getRole = (message) => typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
21643
21709
  const runtimeEntries = this.runtimeMessages.map((entry, index) => ({
21644
21710
  message: entry.message,
21645
21711
  index: parsedMessages.length + index,
21646
21712
  source: "runtime",
21647
21713
  runtimeKey: entry.key
21648
- }));
21714
+ })).filter((entry) => {
21715
+ const meta = entry.message.meta && typeof entry.message.meta === "object" && !Array.isArray(entry.message.meta) ? entry.message.meta : {};
21716
+ if (meta.runtimeInputAck !== true) return true;
21717
+ const runtimeText = flattenContent(entry.message.content).replace(/\s+/g, " ").trim();
21718
+ if (!runtimeText) return false;
21719
+ return !parsedEntries.some((parsedEntry) => {
21720
+ const parsedRole = getRole(parsedEntry.message);
21721
+ if (parsedRole !== "user" && parsedRole !== "human") return false;
21722
+ const parsedText = flattenContent(parsedEntry.message.content).replace(/\s+/g, " ").trim();
21723
+ return parsedText === runtimeText;
21724
+ });
21725
+ });
21649
21726
  const getTime = (message) => {
21650
21727
  const value = typeof message.receivedAt === "number" ? message.receivedAt : typeof message.timestamp === "number" ? message.timestamp : 0;
21651
21728
  return Number.isFinite(value) && value > 0 ? value : 0;
21652
21729
  };
21653
- const getRole = (message) => typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
21654
21730
  const isRuntimeOverlay = (entry) => {
21655
21731
  if (entry.source !== "runtime") return false;
21656
21732
  const key = typeof entry.runtimeKey === "string" ? entry.runtimeKey.trim().toLowerCase() : "";