@adhdev/daemon-standalone 0.9.82-rc.350 → 0.9.82-rc.352
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 +524 -209
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/vendor/mcp-server/index.js +90 -8
- package/vendor/mcp-server/index.js.map +1 -1
package/package.json
CHANGED
|
@@ -4071,6 +4071,81 @@ async function meshSendTask(ctx, args) {
|
|
|
4071
4071
|
return JSON.stringify(failure);
|
|
4072
4072
|
}
|
|
4073
4073
|
}
|
|
4074
|
+
function classifyReadChatTransportCause(error) {
|
|
4075
|
+
const message = (error instanceof Error ? error.message : String(error ?? "")).toLowerCase();
|
|
4076
|
+
if (/not acknowledged|delivery failure|channel never opened|connect timed out|not connected|datachannel|disconnected|\bclosed\b|offline|no route|failed to initiate p2p|p2p mesh is not available|connect queue full/.test(message)) {
|
|
4077
|
+
return "not_connected";
|
|
4078
|
+
}
|
|
4079
|
+
return "saturated";
|
|
4080
|
+
}
|
|
4081
|
+
function resolveCachedMeshSessionPreviewFromLedger(ctx, nodeId, sessionId) {
|
|
4082
|
+
const entries = (0, import_daemon_core.readLedgerEntries)(ctx.mesh.id, { tail: 200 });
|
|
4083
|
+
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
4084
|
+
const entry = entries[i];
|
|
4085
|
+
const payload = entry.payload && typeof entry.payload === "object" && !Array.isArray(entry.payload) ? entry.payload : {};
|
|
4086
|
+
const entryNodeId = readString(entry.nodeId) || readString(payload.nodeId) || readString(payload.meshNodeId);
|
|
4087
|
+
if (entryNodeId && entryNodeId !== nodeId) continue;
|
|
4088
|
+
const entrySessionId = readString(entry.sessionId) || readString(payload.targetSessionId) || readString(payload.sessionId) || readString(payload.instanceId);
|
|
4089
|
+
if (entrySessionId !== sessionId) continue;
|
|
4090
|
+
const metadataEvent = payload.metadataEvent && typeof payload.metadataEvent === "object" && !Array.isArray(payload.metadataEvent) ? payload.metadataEvent : payload;
|
|
4091
|
+
const preview = (0, import_daemon_core.resolveMeshSurfacedSessionPreview)(metadataEvent);
|
|
4092
|
+
if (preview) {
|
|
4093
|
+
return { ...preview, ledgerKind: entry.kind, timestamp: entry.timestamp };
|
|
4094
|
+
}
|
|
4095
|
+
}
|
|
4096
|
+
return void 0;
|
|
4097
|
+
}
|
|
4098
|
+
function buildMeshReadChatCacheFallback(ctx, args, node, error) {
|
|
4099
|
+
const classification = (0, import_daemon_core.classifyP2pRelayFailure)(error, { command: "read_chat", targetDaemonId: node.daemonId });
|
|
4100
|
+
const cause = classifyReadChatTransportCause(error);
|
|
4101
|
+
const errorMessage = error instanceof Error ? error.message : String(error ?? "");
|
|
4102
|
+
const causeNote = cause === "not_connected" ? "the worker daemon is not currently connected over P2P (no live channel)" : "the worker daemon is connected but saturated \u2014 it acknowledged the request but did not return the transcript within the deadline";
|
|
4103
|
+
const cached = resolveCachedMeshSessionPreviewFromLedger(ctx, args.node_id, args.session_id);
|
|
4104
|
+
if (cached) {
|
|
4105
|
+
return JSON.stringify({
|
|
4106
|
+
success: true,
|
|
4107
|
+
source: "coordinator_cache_fallback",
|
|
4108
|
+
fallback: true,
|
|
4109
|
+
nodeId: args.node_id,
|
|
4110
|
+
sessionId: args.session_id,
|
|
4111
|
+
transport: "p2p",
|
|
4112
|
+
transportFailure: {
|
|
4113
|
+
code: classification.code,
|
|
4114
|
+
reason: classification.reason,
|
|
4115
|
+
cause,
|
|
4116
|
+
error: errorMessage
|
|
4117
|
+
},
|
|
4118
|
+
advisory: `Live transcript unavailable (${causeNote}). Showing the cached coordinator-side summary surfaced from the worker's last completion/status event \u2014 a stale point-in-time summary, NOT the live transcript. The full transcript requires a live P2P read_chat once the peer is reachable.`,
|
|
4119
|
+
fullTranscriptRequiresP2p: true,
|
|
4120
|
+
summary: cached.preview,
|
|
4121
|
+
messages: [{
|
|
4122
|
+
role: cached.role,
|
|
4123
|
+
content: cached.preview,
|
|
4124
|
+
cached: true,
|
|
4125
|
+
...cached.receivedAt ? { receivedAt: cached.receivedAt } : {}
|
|
4126
|
+
}],
|
|
4127
|
+
cachedPreview: {
|
|
4128
|
+
role: cached.role,
|
|
4129
|
+
ledgerKind: cached.ledgerKind,
|
|
4130
|
+
ledgerTimestamp: cached.timestamp,
|
|
4131
|
+
...cached.receivedAt ? { receivedAt: cached.receivedAt } : {}
|
|
4132
|
+
}
|
|
4133
|
+
}, null, 2);
|
|
4134
|
+
}
|
|
4135
|
+
const failure = buildCoordinatorP2pRelayFailure(error, {
|
|
4136
|
+
command: "read_chat",
|
|
4137
|
+
targetDaemonId: node.daemonId,
|
|
4138
|
+
nodeId: args.node_id,
|
|
4139
|
+
sessionId: args.session_id
|
|
4140
|
+
});
|
|
4141
|
+
return JSON.stringify({
|
|
4142
|
+
...failure,
|
|
4143
|
+
cause,
|
|
4144
|
+
cachedSummaryAvailable: false,
|
|
4145
|
+
fullTranscriptRequiresP2p: true,
|
|
4146
|
+
advisory: `Live transcript unavailable (${causeNote}) and no cached coordinator-side summary exists for this session yet (no completion/status event has been surfaced). The full transcript requires a live P2P read_chat once the peer is reachable.`
|
|
4147
|
+
}, null, 2);
|
|
4148
|
+
}
|
|
4074
4149
|
async function meshReadChat(ctx, args) {
|
|
4075
4150
|
const node = await findOptionalNodeWithRefresh(ctx, args.node_id);
|
|
4076
4151
|
if (!node) {
|
|
@@ -4079,14 +4154,21 @@ async function meshReadChat(ctx, args) {
|
|
|
4079
4154
|
await drainCoordinatorPendingEvents(ctx, { nodeIds: [args.node_id] });
|
|
4080
4155
|
const cached = resolveMeshSessionProviderMetadata(ctx, args.node_id, args.session_id);
|
|
4081
4156
|
const providerSessionId = typeof args.provider_session_id === "string" && args.provider_session_id.trim() ? args.provider_session_id.trim() : cached?.providerSessionId;
|
|
4082
|
-
const
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4157
|
+
const isLocalNode = isLocalControlPlaneNode(ctx, node);
|
|
4158
|
+
let result;
|
|
4159
|
+
try {
|
|
4160
|
+
result = await commandForNode(ctx, node, "read_chat", {
|
|
4161
|
+
sessionId: args.session_id,
|
|
4162
|
+
targetSessionId: args.session_id,
|
|
4163
|
+
workspace: node.workspace,
|
|
4164
|
+
...cached?.providerType ? { agentType: cached.providerType, providerType: cached.providerType } : {},
|
|
4165
|
+
...providerSessionId ? { providerSessionId } : {},
|
|
4166
|
+
tailLimit: args.tail ?? 10
|
|
4167
|
+
});
|
|
4168
|
+
} catch (e) {
|
|
4169
|
+
if (isLocalNode || !(0, import_daemon_core.isP2pRelayTransportFailure)(e)) throw e;
|
|
4170
|
+
return buildMeshReadChatCacheFallback(ctx, args, node, e);
|
|
4171
|
+
}
|
|
4090
4172
|
const payload = annotateRapidReadChatAdvisory(unwrapCommandPayload(result), {
|
|
4091
4173
|
key: `mesh:${args.node_id}:${args.session_id}`,
|
|
4092
4174
|
toolName: "mesh_read_chat",
|