@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 +107 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +107 -28
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/commands/chat-commands.ts +119 -15
- package/src/mesh/mesh-active-work.ts +13 -1
- package/src/providers/chat-message-normalization.ts +4 -11
- package/src/providers/cli-provider-instance.ts +2 -1
package/dist/index.mjs
CHANGED
|
@@ -9164,7 +9164,19 @@ function sessionStatusFromNodes(nodes, nodeId, sessionId) {
|
|
|
9164
9164
|
if (!node) return { staleReason: "direct task node is no longer in the live mesh" };
|
|
9165
9165
|
if (!sessionId) return {};
|
|
9166
9166
|
const candidates = [];
|
|
9167
|
-
for (const value of [
|
|
9167
|
+
for (const value of [
|
|
9168
|
+
node.sessions,
|
|
9169
|
+
node.activeSessions,
|
|
9170
|
+
node.active_sessions,
|
|
9171
|
+
node.activeSessionDetails,
|
|
9172
|
+
node.active_session_details,
|
|
9173
|
+
node.sessionDetails,
|
|
9174
|
+
node.session_details,
|
|
9175
|
+
node.lastProbe?.sessions,
|
|
9176
|
+
node.last_probe?.sessions,
|
|
9177
|
+
node.lastProbe?.status?.sessions,
|
|
9178
|
+
node.last_probe?.status?.sessions
|
|
9179
|
+
]) {
|
|
9168
9180
|
if (Array.isArray(value)) candidates.push(...value);
|
|
9169
9181
|
}
|
|
9170
9182
|
for (const value of [node.activeSession, node.active_session, node.currentSession, node.current_session, node.runtimeSession, node.runtime_session, node.session]) {
|
|
@@ -11508,15 +11520,6 @@ function extractFinalSummaryFromMessages(messages, maxChars = DEFAULT_FINAL_SUMM
|
|
|
11508
11520
|
if (text) return text.slice(0, maxChars);
|
|
11509
11521
|
}
|
|
11510
11522
|
}
|
|
11511
|
-
for (let i = messages.length - 1; i >= 0; i--) {
|
|
11512
|
-
const msg = messages[i];
|
|
11513
|
-
if (!msg) continue;
|
|
11514
|
-
const classification = classifyChatMessageVisibility(msg);
|
|
11515
|
-
if (classification.isUserFacing) {
|
|
11516
|
-
const text = flattenContent(msg.content).trim();
|
|
11517
|
-
if (text) return text.slice(0, maxChars);
|
|
11518
|
-
}
|
|
11519
|
-
}
|
|
11520
11523
|
return "";
|
|
11521
11524
|
}
|
|
11522
11525
|
var BUILTIN_CHAT_MESSAGE_KINDS = ["standard", "thought", "tool", "terminal", "system"];
|
|
@@ -15737,6 +15740,13 @@ function getCurrentManagerKey(h) {
|
|
|
15737
15740
|
function getTargetedCliAdapter(h, args, providerType) {
|
|
15738
15741
|
return h.getCliAdapter(args?.targetSessionId || providerType || h.currentSession?.providerType || h.currentManagerKey);
|
|
15739
15742
|
}
|
|
15743
|
+
function getExplicitHistorySessionId(args) {
|
|
15744
|
+
const explicit = typeof args?.historySessionId === "string" ? args.historySessionId.trim() : "";
|
|
15745
|
+
if (explicit) return explicit;
|
|
15746
|
+
const explicitProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : "";
|
|
15747
|
+
if (explicitProviderSessionId) return explicitProviderSessionId;
|
|
15748
|
+
return void 0;
|
|
15749
|
+
}
|
|
15740
15750
|
function getTargetInstance(h, args) {
|
|
15741
15751
|
const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
|
|
15742
15752
|
const sessionId = targetSessionId || h.currentSession?.sessionId || "";
|
|
@@ -15805,13 +15815,14 @@ async function waitOnceForFreshHermesCliStart(adapter, log) {
|
|
|
15805
15815
|
await sleep(HERMES_CLI_STARTING_SEND_SETTLE_MS);
|
|
15806
15816
|
}
|
|
15807
15817
|
function getHistorySessionId(h, args) {
|
|
15808
|
-
const explicit =
|
|
15818
|
+
const explicit = getExplicitHistorySessionId(args);
|
|
15809
15819
|
if (explicit) return explicit;
|
|
15810
|
-
const explicitProviderSessionId = typeof args?.providerSessionId === "string" ? args.providerSessionId.trim() : "";
|
|
15811
|
-
if (explicitProviderSessionId) return explicitProviderSessionId;
|
|
15812
15820
|
const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
|
|
15813
15821
|
if (!targetSessionId) return void 0;
|
|
15814
|
-
const
|
|
15822
|
+
const session = h.ctx.sessionRegistry?.get(targetSessionId);
|
|
15823
|
+
const registeredProviderSessionId = typeof session?.providerSessionId === "string" ? session.providerSessionId.trim() : "";
|
|
15824
|
+
if (registeredProviderSessionId) return registeredProviderSessionId;
|
|
15825
|
+
const instance = getTargetInstance(h, args);
|
|
15815
15826
|
const state = instance?.getState?.();
|
|
15816
15827
|
const providerSessionId = typeof state?.providerSessionId === "string" ? state.providerSessionId.trim() : "";
|
|
15817
15828
|
if (providerSessionId) return providerSessionId;
|
|
@@ -15822,6 +15833,15 @@ function getHistorySessionId(h, args) {
|
|
|
15822
15833
|
}
|
|
15823
15834
|
return targetSessionId;
|
|
15824
15835
|
}
|
|
15836
|
+
function resolveCliNativeHistorySessionId(args, currentHistorySessionId, parsedProviderSessionId) {
|
|
15837
|
+
const explicit = getExplicitHistorySessionId(args);
|
|
15838
|
+
if (explicit) return explicit;
|
|
15839
|
+
const parsed = typeof parsedProviderSessionId === "string" ? parsedProviderSessionId.trim() : "";
|
|
15840
|
+
const current = typeof currentHistorySessionId === "string" ? currentHistorySessionId.trim() : "";
|
|
15841
|
+
const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
|
|
15842
|
+
if (parsed && (!current || current === targetSessionId)) return parsed;
|
|
15843
|
+
return current || parsed || void 0;
|
|
15844
|
+
}
|
|
15825
15845
|
function getInteractionId(args) {
|
|
15826
15846
|
return typeof args?._interactionId === "string" && args._interactionId.trim() ? args._interactionId.trim() : void 0;
|
|
15827
15847
|
}
|
|
@@ -15966,6 +15986,29 @@ function supportsCliNativeTranscript(providerType, provider) {
|
|
|
15966
15986
|
if (CLI_NATIVE_TRANSCRIPT_PROVIDERS.has(providerType)) return true;
|
|
15967
15987
|
return provider?.category === "cli" && isNativeSourceCanonicalHistory(provider?.canonicalHistory);
|
|
15968
15988
|
}
|
|
15989
|
+
function getComparableVisibleText(message) {
|
|
15990
|
+
if (!message) return "";
|
|
15991
|
+
const role = String(message.role || "").trim().toLowerCase();
|
|
15992
|
+
if (role !== "user" && role !== "assistant") return "";
|
|
15993
|
+
const kind = String(message.kind || "standard").trim().toLowerCase();
|
|
15994
|
+
if (kind && kind !== "standard") return "";
|
|
15995
|
+
const content = flattenContent(message.content).replace(/\s+/g, " ").trim();
|
|
15996
|
+
return content;
|
|
15997
|
+
}
|
|
15998
|
+
function hasOverlappingVisibleConversationText(nativeMessages, ptyMessages) {
|
|
15999
|
+
const nativeTexts = nativeMessages.map(getComparableVisibleText).filter(Boolean);
|
|
16000
|
+
const ptyTexts = ptyMessages.map(getComparableVisibleText).filter(Boolean);
|
|
16001
|
+
if (nativeTexts.length === 0 || ptyTexts.length === 0) return false;
|
|
16002
|
+
for (const nativeText of nativeTexts) {
|
|
16003
|
+
for (const ptyText of ptyTexts) {
|
|
16004
|
+
if (nativeText === ptyText) return true;
|
|
16005
|
+
const shorter = nativeText.length <= ptyText.length ? nativeText : ptyText;
|
|
16006
|
+
const longer = nativeText.length <= ptyText.length ? ptyText : nativeText;
|
|
16007
|
+
if (shorter.length >= 32 && longer.includes(shorter)) return true;
|
|
16008
|
+
}
|
|
16009
|
+
}
|
|
16010
|
+
return false;
|
|
16011
|
+
}
|
|
15969
16012
|
function hasSafeNativeHistoryMapping(args) {
|
|
15970
16013
|
const explicitSessionId = String(args.historySessionId || args.providerSessionId || "").trim();
|
|
15971
16014
|
if (explicitSessionId) {
|
|
@@ -15975,7 +16018,10 @@ function hasSafeNativeHistoryMapping(args) {
|
|
|
15975
16018
|
}
|
|
15976
16019
|
const workspace = String(args.workspace || "").trim();
|
|
15977
16020
|
if (!workspace) return false;
|
|
15978
|
-
|
|
16021
|
+
const workspaceMatches = args.nativeMessages.some((message) => String(message?.workspace || "").trim() === workspace);
|
|
16022
|
+
if (!workspaceMatches) return false;
|
|
16023
|
+
if (!args.requireWorkspaceContentOverlap) return true;
|
|
16024
|
+
return hasOverlappingVisibleConversationText(args.nativeMessages, args.ptyMessages || []);
|
|
15979
16025
|
}
|
|
15980
16026
|
function readCliProviderNativeHistory(agentStr, args) {
|
|
15981
16027
|
const sessionHistory = readProviderChatHistory(agentStr, {
|
|
@@ -15988,8 +16034,8 @@ function readCliProviderNativeHistory(agentStr, args) {
|
|
|
15988
16034
|
historyBehavior: args.historyBehavior,
|
|
15989
16035
|
scripts: args.scripts
|
|
15990
16036
|
});
|
|
15991
|
-
if (sessionHistory.source !== "native-unavailable" || !args.historySessionId || !args.workspace) {
|
|
15992
|
-
return { ...sessionHistory, lookup: "session" };
|
|
16037
|
+
if (sessionHistory.source !== "native-unavailable" || args.exactSessionScoped || !args.historySessionId || !args.workspace) {
|
|
16038
|
+
return { ...sessionHistory, lookup: args.historySessionId ? "session" : "workspace" };
|
|
15993
16039
|
}
|
|
15994
16040
|
const workspaceHistory = readProviderChatHistory(agentStr, {
|
|
15995
16041
|
canonicalHistory: args.canonicalHistory,
|
|
@@ -16014,6 +16060,19 @@ function isNativeHistoryFreshEnough(args) {
|
|
|
16014
16060
|
function shouldPreserveReadChatPayloadField(key) {
|
|
16015
16061
|
return key === "messageSource" || key === "transcriptProvenance";
|
|
16016
16062
|
}
|
|
16063
|
+
function updateMessageSourceReturnedCount(value, returnedMessageCount) {
|
|
16064
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return value;
|
|
16065
|
+
const record = value;
|
|
16066
|
+
const coverage = record.coverage && typeof record.coverage === "object" && !Array.isArray(record.coverage) ? record.coverage : void 0;
|
|
16067
|
+
if (!coverage) return value;
|
|
16068
|
+
return {
|
|
16069
|
+
...record,
|
|
16070
|
+
coverage: {
|
|
16071
|
+
...coverage,
|
|
16072
|
+
returnedMessageCount
|
|
16073
|
+
}
|
|
16074
|
+
};
|
|
16075
|
+
}
|
|
16017
16076
|
function deriveHistoryDedupKey(message) {
|
|
16018
16077
|
const unitKey = typeof message._unitKey === "string" ? message._unitKey.trim() : "";
|
|
16019
16078
|
if (unitKey) return `read_chat:${unitKey}`;
|
|
@@ -16125,6 +16184,13 @@ function buildReadChatCommandResult(payload, args) {
|
|
|
16125
16184
|
const visibleMessages = filterUserFacingChatMessages(messages);
|
|
16126
16185
|
const sync = buildFullTail(visibleMessages, normalizeReadChatTailLimit(args));
|
|
16127
16186
|
const hiddenMsgCount = Math.max(0, messages.length - visibleMessages.length);
|
|
16187
|
+
const preservedPayloadFields = Object.fromEntries(Object.entries(payload).filter(([key]) => shouldPreserveReadChatPayloadField(key)));
|
|
16188
|
+
if (preservedPayloadFields.messageSource) {
|
|
16189
|
+
preservedPayloadFields.messageSource = updateMessageSourceReturnedCount(preservedPayloadFields.messageSource, sync.messages.length);
|
|
16190
|
+
}
|
|
16191
|
+
if (preservedPayloadFields.transcriptProvenance) {
|
|
16192
|
+
preservedPayloadFields.transcriptProvenance = updateMessageSourceReturnedCount(preservedPayloadFields.transcriptProvenance, sync.messages.length);
|
|
16193
|
+
}
|
|
16128
16194
|
const returnedDebugReadChat = debugReadChat ? {
|
|
16129
16195
|
...debugReadChat,
|
|
16130
16196
|
fullMsgCount: typeof debugReadChat.fullMsgCount === "number" ? debugReadChat.fullMsgCount : messages.length,
|
|
@@ -16135,7 +16201,7 @@ function buildReadChatCommandResult(payload, args) {
|
|
|
16135
16201
|
return {
|
|
16136
16202
|
success: true,
|
|
16137
16203
|
...validatedPayload,
|
|
16138
|
-
...
|
|
16204
|
+
...preservedPayloadFields,
|
|
16139
16205
|
messages: sync.messages,
|
|
16140
16206
|
totalMessages: sync.totalMessages,
|
|
16141
16207
|
...returnedDebugReadChat ? { debugReadChat: returnedDebugReadChat } : {}
|
|
@@ -16610,17 +16676,23 @@ async function handleReadChat(h, args) {
|
|
|
16610
16676
|
returnedMessages.length,
|
|
16611
16677
|
200
|
|
16612
16678
|
);
|
|
16679
|
+
const nativeHistorySessionId = resolveCliNativeHistorySessionId(args, historySessionId, providerSessionId);
|
|
16680
|
+
const targetSessionId = typeof args?.targetSessionId === "string" ? args.targetSessionId.trim() : "";
|
|
16681
|
+
const exactNativeHistoryScope = Boolean(
|
|
16682
|
+
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()
|
|
16683
|
+
);
|
|
16613
16684
|
let nativeHistory = null;
|
|
16614
16685
|
try {
|
|
16615
16686
|
nativeHistory = readCliProviderNativeHistory(agentStr, {
|
|
16616
16687
|
canonicalHistory: provider?.canonicalHistory,
|
|
16617
|
-
historySessionId,
|
|
16688
|
+
historySessionId: nativeHistorySessionId,
|
|
16618
16689
|
workspace,
|
|
16619
16690
|
offset: 0,
|
|
16620
16691
|
limit: nativeHistoryLimit,
|
|
16621
16692
|
excludeRecentCount: 0,
|
|
16622
16693
|
historyBehavior: provider?.historyBehavior,
|
|
16623
|
-
scripts: provider?.scripts
|
|
16694
|
+
scripts: provider?.scripts,
|
|
16695
|
+
exactSessionScoped: exactNativeHistoryScope
|
|
16624
16696
|
});
|
|
16625
16697
|
} catch (error) {
|
|
16626
16698
|
const fallbackReason = `native_history_error:${error?.message || String(error)}`;
|
|
@@ -16636,13 +16708,15 @@ async function handleReadChat(h, args) {
|
|
|
16636
16708
|
}
|
|
16637
16709
|
if (nativeHistory) {
|
|
16638
16710
|
const nativeMessages = Array.isArray(nativeHistory.messages) ? normalizeNativeHistoryMessages(agentStr, nativeHistory.messages) : [];
|
|
16639
|
-
const historyProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId : readHistorySessionIdFromMessages(nativeMessages) || historySessionId;
|
|
16711
|
+
const historyProviderSessionId = typeof nativeHistory?.providerSessionId === "string" ? nativeHistory.providerSessionId : readHistorySessionIdFromMessages(nativeMessages) || nativeHistorySessionId || historySessionId;
|
|
16640
16712
|
const lookup = nativeHistory.lookup === "workspace" ? "workspace" : "session";
|
|
16641
16713
|
const safeMapping = hasSafeNativeHistoryMapping({
|
|
16642
|
-
historySessionId: lookup === "workspace" ? void 0 :
|
|
16643
|
-
providerSessionId: lookup === "workspace" ? void 0 : providerSessionId,
|
|
16714
|
+
historySessionId: lookup === "workspace" ? void 0 : nativeHistorySessionId,
|
|
16715
|
+
providerSessionId: lookup === "workspace" ? void 0 : historyProviderSessionId || providerSessionId,
|
|
16644
16716
|
workspace,
|
|
16645
|
-
nativeMessages
|
|
16717
|
+
nativeMessages,
|
|
16718
|
+
ptyMessages: returnedMessages,
|
|
16719
|
+
requireWorkspaceContentOverlap: lookup === "workspace" && !exactNativeHistoryScope
|
|
16646
16720
|
});
|
|
16647
16721
|
const freshEnough = isNativeHistoryFreshEnough({
|
|
16648
16722
|
sourceMtimeMs: nativeHistory.sourceMtimeMs,
|
|
@@ -16657,7 +16731,7 @@ async function handleReadChat(h, args) {
|
|
|
16657
16731
|
messageSource = buildCliMessageSourceProvenance({
|
|
16658
16732
|
selected: "native-history",
|
|
16659
16733
|
provider: adapter.cliType,
|
|
16660
|
-
nativeHandle: selectedProviderSessionId || historySessionId,
|
|
16734
|
+
nativeHandle: selectedProviderSessionId || nativeHistorySessionId || historySessionId,
|
|
16661
16735
|
nativeSource: nativeHistory.source,
|
|
16662
16736
|
sourcePath: nativeHistory.sourcePath,
|
|
16663
16737
|
sourceMtimeMs: nativeHistory.sourceMtimeMs,
|
|
@@ -16680,7 +16754,7 @@ async function handleReadChat(h, args) {
|
|
|
16680
16754
|
messageSource = buildCliMessageSourceProvenance({
|
|
16681
16755
|
selected: "pty-parser",
|
|
16682
16756
|
provider: adapter.cliType,
|
|
16683
|
-
nativeHandle: historyProviderSessionId || historySessionId,
|
|
16757
|
+
nativeHandle: historyProviderSessionId || nativeHistorySessionId || historySessionId,
|
|
16684
16758
|
fallbackReason,
|
|
16685
16759
|
nativeSource: nativeHistory.source,
|
|
16686
16760
|
sourcePath: nativeHistory.sourcePath,
|
|
@@ -16724,6 +16798,9 @@ async function handleReadChat(h, args) {
|
|
|
16724
16798
|
try {
|
|
16725
16799
|
const agentStr = provider?.type || args?.agentType || getCurrentProviderType(h);
|
|
16726
16800
|
const workspace = typeof args?.workspace === "string" ? args.workspace : typeof h.currentSession?.workspace === "string" ? h.currentSession.workspace : void 0;
|
|
16801
|
+
const exactNativeHistoryScope = Boolean(
|
|
16802
|
+
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()
|
|
16803
|
+
);
|
|
16727
16804
|
const history = supportsCliNativeTranscript(agentStr, provider) && isNativeSourceCanonicalHistory(provider?.canonicalHistory) ? readCliProviderNativeHistory(agentStr, {
|
|
16728
16805
|
canonicalHistory: provider?.canonicalHistory,
|
|
16729
16806
|
historySessionId,
|
|
@@ -16732,7 +16809,8 @@ async function handleReadChat(h, args) {
|
|
|
16732
16809
|
limit: historyLimit,
|
|
16733
16810
|
excludeRecentCount: 0,
|
|
16734
16811
|
historyBehavior: provider?.historyBehavior,
|
|
16735
|
-
scripts: provider?.scripts
|
|
16812
|
+
scripts: provider?.scripts,
|
|
16813
|
+
exactSessionScoped: exactNativeHistoryScope
|
|
16736
16814
|
}) : readProviderChatHistory(agentStr, {
|
|
16737
16815
|
canonicalHistory: provider?.canonicalHistory,
|
|
16738
16816
|
historySessionId,
|
|
@@ -19495,6 +19573,7 @@ var CliProviderInstance = class {
|
|
|
19495
19573
|
}
|
|
19496
19574
|
const runtime = this.adapter.getRuntimeMetadata();
|
|
19497
19575
|
this.maybeAppendRuntimeRecoveryMessage(runtime);
|
|
19576
|
+
const activeChatId = this.providerSessionId || runtime?.runtimeId || this.instanceId;
|
|
19498
19577
|
let parsedMessages = Array.isArray(parsedStatus?.messages) ? parsedStatus.messages : [];
|
|
19499
19578
|
const historyMessageCount = Number.isFinite(parsedStatus?.historyMessageCount) ? Math.max(0, Number(parsedStatus.historyMessageCount)) : null;
|
|
19500
19579
|
if (historyMessageCount !== null) {
|
|
@@ -19550,7 +19629,7 @@ var CliProviderInstance = class {
|
|
|
19550
19629
|
status: visibleStatus,
|
|
19551
19630
|
mode: this.presentationMode,
|
|
19552
19631
|
activeChat: {
|
|
19553
|
-
id:
|
|
19632
|
+
id: activeChatId,
|
|
19554
19633
|
title: parsedStatus?.title || dirName,
|
|
19555
19634
|
status: activeChatStatus,
|
|
19556
19635
|
messages: mergedMessages,
|