@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.js +106 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +108 -16
- package/dist/index.mjs.map +1 -1
- package/dist/providers/cli-provider-instance.d.ts +1 -0
- package/package.json +1 -1
- package/src/commands/chat-commands.ts +97 -8
- package/src/providers/cli-provider-instance.ts +46 -5
package/dist/index.js
CHANGED
|
@@ -17107,9 +17107,9 @@ function buildCliMessageSourceProvenance(args) {
|
|
|
17107
17107
|
ptyMessageCount: ptyMessages.length,
|
|
17108
17108
|
returnedMessageCount: returnedMessages.length,
|
|
17109
17109
|
safeMapping: args.safeMapping === true,
|
|
17110
|
-
// true when
|
|
17111
|
-
//
|
|
17112
|
-
ptyMessagesSuppressed: args.selected === "native-history"
|
|
17110
|
+
// true when PTY message bodies are suppressed and must not be treated as
|
|
17111
|
+
// chat content. PTY may still contribute status/approval/screen evidence.
|
|
17112
|
+
ptyMessagesSuppressed: args.selected === "native-history" || args.ptyStatusApprovalOnly === true
|
|
17113
17113
|
}
|
|
17114
17114
|
};
|
|
17115
17115
|
}
|
|
@@ -17125,6 +17125,42 @@ function buildNativeHistoryFallbackReason(args) {
|
|
|
17125
17125
|
if (!args.freshEnough) return "native_history_stale";
|
|
17126
17126
|
return "native_history_not_selected";
|
|
17127
17127
|
}
|
|
17128
|
+
function isUnsafeNativeTranscriptFallback(reason) {
|
|
17129
|
+
const value = String(reason || "").trim();
|
|
17130
|
+
return value.startsWith("native_history_unavailable") || value === "native_history_not_safely_mapped" || value === "native_history_stale" || value === "native_history_partial";
|
|
17131
|
+
}
|
|
17132
|
+
function coerceUnsafeNativeFallbackStatus(status, activeModal) {
|
|
17133
|
+
if (status === "waiting_approval" && activeModal) return status;
|
|
17134
|
+
return "idle";
|
|
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
|
+
}
|
|
17128
17164
|
function supportsCliNativeTranscript(providerType, provider) {
|
|
17129
17165
|
if (CLI_NATIVE_TRANSCRIPT_PROVIDERS.has(providerType)) return true;
|
|
17130
17166
|
return provider?.category === "cli" && isNativeSourceCanonicalHistory(provider?.canonicalHistory);
|
|
@@ -17860,6 +17896,7 @@ async function handleReadChat(h, args) {
|
|
|
17860
17896
|
let selectedProviderSessionId = providerSessionId;
|
|
17861
17897
|
let selectedTranscriptAuthority = transcriptAuthority;
|
|
17862
17898
|
let selectedCoverage = coverage;
|
|
17899
|
+
let selectedStatus = returnedStatus;
|
|
17863
17900
|
const sessionWorkspace = typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : typeof adapter.workingDir === "string" ? adapter.workingDir : void 0;
|
|
17864
17901
|
const intendedWorkspace = typeof args?.workspace === "string" ? args.workspace : void 0;
|
|
17865
17902
|
let messageSource = buildCliMessageSourceProvenance({
|
|
@@ -17971,6 +18008,22 @@ async function handleReadChat(h, args) {
|
|
|
17971
18008
|
safeMapping,
|
|
17972
18009
|
freshEnough
|
|
17973
18010
|
});
|
|
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;
|
|
18021
|
+
if (unsafeNativeFallback) {
|
|
18022
|
+
selectedMessages = safeDaemonMessages;
|
|
18023
|
+
selectedTranscriptAuthority = safeDaemonMessages.length > 0 ? "daemon" : void 0;
|
|
18024
|
+
selectedCoverage = safeDaemonMessages.length > 0 ? "tail" : void 0;
|
|
18025
|
+
selectedStatus = coerceUnsafeNativeFallbackStatus(returnedStatus, activeModal);
|
|
18026
|
+
}
|
|
17974
18027
|
messageSource = buildCliMessageSourceProvenance({
|
|
17975
18028
|
selected: "pty-parser",
|
|
17976
18029
|
provider: adapter.cliType,
|
|
@@ -17987,18 +18040,22 @@ async function handleReadChat(h, args) {
|
|
|
17987
18040
|
unavailableReason,
|
|
17988
18041
|
nativeMessages,
|
|
17989
18042
|
ptyMessages: returnedMessages,
|
|
17990
|
-
returnedMessages,
|
|
18043
|
+
returnedMessages: unsafeNativeFallback ? safeDaemonMessages : returnedMessages,
|
|
17991
18044
|
safeMapping,
|
|
17992
18045
|
freshEnough,
|
|
17993
|
-
ptyStatusApprovalOnly:
|
|
18046
|
+
ptyStatusApprovalOnly: unsafeNativeFallback
|
|
17994
18047
|
});
|
|
18048
|
+
if (unsafeNativeFallback && exactRuntimeMirrorMessages.length > 0) {
|
|
18049
|
+
messageSource.selectedDaemonSource = "exact-runtime-mirror";
|
|
18050
|
+
messageSource.transcriptAuthority = "daemon";
|
|
18051
|
+
}
|
|
17995
18052
|
}
|
|
17996
18053
|
}
|
|
17997
18054
|
}
|
|
17998
18055
|
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}`);
|
|
17999
18056
|
return buildReadChatCommandResult({
|
|
18000
18057
|
messages: selectedMessages,
|
|
18001
|
-
status:
|
|
18058
|
+
status: selectedStatus,
|
|
18002
18059
|
activeModal,
|
|
18003
18060
|
messageSource,
|
|
18004
18061
|
transcriptProvenance: messageSource,
|
|
@@ -18007,10 +18064,10 @@ async function handleReadChat(h, args) {
|
|
|
18007
18064
|
targetSessionId: String(args?.targetSessionId || ""),
|
|
18008
18065
|
adapterStatus: String(adapterStatus.status || ""),
|
|
18009
18066
|
parsedStatus: String(parsedRecord.status || ""),
|
|
18010
|
-
returnedStatus: String(
|
|
18067
|
+
returnedStatus: String(selectedStatus || ""),
|
|
18011
18068
|
selectedMessageSource: messageSource.selected,
|
|
18012
18069
|
messageSource,
|
|
18013
|
-
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"),
|
|
18070
|
+
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"),
|
|
18014
18071
|
parsedMsgCount: parsedRecord.messages.length,
|
|
18015
18072
|
returnedMsgCount: selectedMessages.length
|
|
18016
18073
|
},
|
|
@@ -18326,14 +18383,14 @@ async function handleSendChat(h, args) {
|
|
|
18326
18383
|
try {
|
|
18327
18384
|
const hasStructuredParts = input.parts.some((part) => part.type !== "text");
|
|
18328
18385
|
if (hasStructuredParts) {
|
|
18329
|
-
const
|
|
18330
|
-
if (!
|
|
18386
|
+
const target2 = getTargetInstance(h, args);
|
|
18387
|
+
if (!target2 || target2.category !== "cli") {
|
|
18331
18388
|
return { success: false, error: `CLI instance not found for ${provider?.type || args?.agentType || "unknown"}` };
|
|
18332
18389
|
}
|
|
18333
18390
|
assertProviderSupportsDeclaredInput(provider, input);
|
|
18334
18391
|
await waitOnceForFreshHermesCliStart(adapter, _log);
|
|
18335
|
-
|
|
18336
|
-
return _logSendSuccess(`${transport}-instance`,
|
|
18392
|
+
target2.onEvent("send_message", { input });
|
|
18393
|
+
return _logSendSuccess(`${transport}-instance`, target2.type);
|
|
18337
18394
|
}
|
|
18338
18395
|
assertTextOnlyInput(provider, input);
|
|
18339
18396
|
if (!text) return { success: false, error: "text required for PTY send" };
|
|
@@ -18346,6 +18403,10 @@ async function handleSendChat(h, args) {
|
|
|
18346
18403
|
} else {
|
|
18347
18404
|
await adapter.sendMessage(text);
|
|
18348
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
|
+
}
|
|
18349
18410
|
return {
|
|
18350
18411
|
..._logSendSuccess(`${transport}-adapter`, adapter.cliType),
|
|
18351
18412
|
...forceSend ? { forceSent: true } : {}
|
|
@@ -21015,6 +21076,26 @@ var CliProviderInstance = class {
|
|
|
21015
21076
|
this.applyProviderResponse(data, { phase: "immediate" });
|
|
21016
21077
|
}
|
|
21017
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
|
+
}
|
|
21018
21099
|
dispose() {
|
|
21019
21100
|
this.adapter.shutdown();
|
|
21020
21101
|
this.monitor.reset();
|
|
@@ -21624,17 +21705,28 @@ ${effect.notification.body || ""}`.trim();
|
|
|
21624
21705
|
index,
|
|
21625
21706
|
source: "parsed"
|
|
21626
21707
|
}));
|
|
21708
|
+
const getRole = (message) => typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
|
|
21627
21709
|
const runtimeEntries = this.runtimeMessages.map((entry, index) => ({
|
|
21628
21710
|
message: entry.message,
|
|
21629
21711
|
index: parsedMessages.length + index,
|
|
21630
21712
|
source: "runtime",
|
|
21631
21713
|
runtimeKey: entry.key
|
|
21632
|
-
}))
|
|
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
|
+
});
|
|
21633
21726
|
const getTime = (message) => {
|
|
21634
21727
|
const value = typeof message.receivedAt === "number" ? message.receivedAt : typeof message.timestamp === "number" ? message.timestamp : 0;
|
|
21635
21728
|
return Number.isFinite(value) && value > 0 ? value : 0;
|
|
21636
21729
|
};
|
|
21637
|
-
const getRole = (message) => typeof message.role === "string" ? message.role.trim().toLowerCase() : "";
|
|
21638
21730
|
const isRuntimeOverlay = (entry) => {
|
|
21639
21731
|
if (entry.source !== "runtime") return false;
|
|
21640
21732
|
const key = typeof entry.runtimeKey === "string" ? entry.runtimeKey.trim().toLowerCase() : "";
|