@adhdev/daemon-standalone 1.0.38 → 1.0.39-rc.1
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 +2721 -4107
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/vendor/mcp-server/index.js +184 -183
- package/vendor/mcp-server/index.js.map +1 -1
- package/vendor/session-host-daemon/index.js +0 -0
- package/vendor/session-host-daemon/index.mjs +0 -0
|
@@ -36,7 +36,8 @@ __export(index_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(index_exports);
|
|
37
37
|
|
|
38
38
|
// src/transports/ipc.ts
|
|
39
|
-
var
|
|
39
|
+
var import_daemon_core = require("@adhdev/daemon-core");
|
|
40
|
+
var DEFAULT_IPC_PORT = import_daemon_core.IDENTITY.defaultPort;
|
|
40
41
|
var DEFAULT_IPC_PATH = "/ipc";
|
|
41
42
|
var DEFAULT_IPC_COMMAND_TIMEOUT_MS = 15e3;
|
|
42
43
|
var IPC_COMMAND_TIMEOUTS_MS = {
|
|
@@ -621,7 +622,7 @@ function withStatusProbeMarker(args = {}) {
|
|
|
621
622
|
}
|
|
622
623
|
|
|
623
624
|
// src/tools/mesh-tools-internal.ts
|
|
624
|
-
var
|
|
625
|
+
var import_daemon_core4 = require("@adhdev/daemon-core");
|
|
625
626
|
|
|
626
627
|
// src/tools/mesh-tool-shared.ts
|
|
627
628
|
function readString(value) {
|
|
@@ -672,7 +673,7 @@ function elideLargeNestedValue(key, value) {
|
|
|
672
673
|
}
|
|
673
674
|
|
|
674
675
|
// src/tools/mesh-session-helpers.ts
|
|
675
|
-
var
|
|
676
|
+
var import_daemon_core2 = require("@adhdev/daemon-core");
|
|
676
677
|
function readSessionRecordId(session) {
|
|
677
678
|
return readString(session?.id) || readString(session?.sessionId) || readString(session?.session_id) || readString(session?.runtimeSessionId) || readString(session?.runtime_session_id) || readString(session?.instanceId) || readString(session?.instance_id);
|
|
678
679
|
}
|
|
@@ -701,7 +702,7 @@ function isUnmanagedSessionRecord(session) {
|
|
|
701
702
|
return !launchedByCoordinator;
|
|
702
703
|
}
|
|
703
704
|
function isWorkerTaskMode(taskMode, readonly) {
|
|
704
|
-
return !(0,
|
|
705
|
+
return !(0, import_daemon_core2.isTaskReadonly)({ readonly, taskMode });
|
|
705
706
|
}
|
|
706
707
|
function addSessionRecord(target, session) {
|
|
707
708
|
if (!session || typeof session !== "object" || isTerminalSessionRecord(session)) return;
|
|
@@ -766,7 +767,7 @@ function isIdleSessionRecord(session) {
|
|
|
766
767
|
}
|
|
767
768
|
|
|
768
769
|
// src/tools/mesh-node-identity.ts
|
|
769
|
-
var
|
|
770
|
+
var import_daemon_core3 = require("@adhdev/daemon-core");
|
|
770
771
|
function resolveCoordinatorNode(ctx) {
|
|
771
772
|
const preferredNodeId = typeof ctx.mesh.coordinator?.preferredNodeId === "string" ? ctx.mesh.coordinator.preferredNodeId.trim() : "";
|
|
772
773
|
if (preferredNodeId) {
|
|
@@ -778,13 +779,13 @@ function resolveCoordinatorNode(ctx) {
|
|
|
778
779
|
if (byMachine) return byMachine;
|
|
779
780
|
}
|
|
780
781
|
if (ctx.localDaemonId) {
|
|
781
|
-
return ctx.mesh.nodes.find((n) => (0,
|
|
782
|
+
return ctx.mesh.nodes.find((n) => (0, import_daemon_core3.daemonIdsEquivalent)(readNodeDaemonId(n), ctx.localDaemonId));
|
|
782
783
|
}
|
|
783
784
|
return void 0;
|
|
784
785
|
}
|
|
785
786
|
function resolveCoordinatorDaemonId(ctx) {
|
|
786
787
|
const resolved = readString(resolveCoordinatorNode(ctx)?.daemonId) || readString(ctx.localDaemonId) || readString(ctx.localMachineId);
|
|
787
|
-
return (0,
|
|
788
|
+
return (0, import_daemon_core3.canonicalDaemonId)(resolved) ?? readString(resolved);
|
|
788
789
|
}
|
|
789
790
|
function readNodeMachineId(node) {
|
|
790
791
|
return readString(node.machineId) || readString(node.machine_id) || readString(node.machine?.id) || readString(node.machine?.machineId) || readString(node.lastProbe?.machineId) || readString(node.last_probe?.machine_id) || readString(node.lastProbe?.machine?.id) || readString(node.lastProbe?.machine?.machineId) || readString(node.last_probe?.machine?.id) || readString(node.last_probe?.machine?.machine_id);
|
|
@@ -851,8 +852,8 @@ function buildNodeMachineIdentity(ctx, node) {
|
|
|
851
852
|
function nodeHasLocalDaemonEvidence(ctx, node) {
|
|
852
853
|
const isLocal = (session) => {
|
|
853
854
|
if (!session || typeof session !== "object") return false;
|
|
854
|
-
if (ctx.localDaemonId && (0,
|
|
855
|
-
if (ctx.localDaemonId && (0,
|
|
855
|
+
if (ctx.localDaemonId && (0, import_daemon_core3.daemonIdsEquivalent)(session.runtime?.owner, ctx.localDaemonId)) return true;
|
|
856
|
+
if (ctx.localDaemonId && (0, import_daemon_core3.daemonIdsEquivalent)(session.daemonClient?.daemonId, ctx.localDaemonId)) return true;
|
|
856
857
|
return false;
|
|
857
858
|
};
|
|
858
859
|
const sessionArrays = [
|
|
@@ -891,7 +892,7 @@ function isDirectLocalNode(ctx, node) {
|
|
|
891
892
|
const machineId = readNodeMachineId(node);
|
|
892
893
|
const daemonId = readNodeDaemonId(node);
|
|
893
894
|
return Boolean(
|
|
894
|
-
ctx.localMachineId && (0,
|
|
895
|
+
ctx.localMachineId && (0, import_daemon_core3.daemonIdsEquivalent)(machineId, ctx.localMachineId) || ctx.localDaemonId && (0, import_daemon_core3.daemonIdsEquivalent)(daemonId, ctx.localDaemonId) || nodeHasLocalDaemonEvidence(ctx, node)
|
|
895
896
|
);
|
|
896
897
|
}
|
|
897
898
|
function isConfiguredCoordinatorNode(ctx, node) {
|
|
@@ -900,8 +901,8 @@ function isConfiguredCoordinatorNode(ctx, node) {
|
|
|
900
901
|
if (!nodeId) return false;
|
|
901
902
|
const nodeDaemonId = readNodeDaemonId(node);
|
|
902
903
|
const nodeMachineId = readNodeMachineId(node);
|
|
903
|
-
if (nodeDaemonId && ctx.localDaemonId && !(0,
|
|
904
|
-
if (nodeMachineId && ctx.localMachineId && !(0,
|
|
904
|
+
if (nodeDaemonId && ctx.localDaemonId && !(0, import_daemon_core3.daemonIdsEquivalent)(nodeDaemonId, ctx.localDaemonId)) return false;
|
|
905
|
+
if (nodeMachineId && ctx.localMachineId && !(0, import_daemon_core3.daemonIdsEquivalent)(nodeMachineId, ctx.localMachineId)) return false;
|
|
905
906
|
const preferredNodeId = readString(ctx.mesh.coordinator?.preferredNodeId) || readString(ctx.mesh.coordinator?.preferred_node_id);
|
|
906
907
|
if (preferredNodeId) return nodeId === preferredNodeId;
|
|
907
908
|
const first = ctx.mesh.nodes?.[0];
|
|
@@ -921,7 +922,7 @@ function getLocalControlPlaneMatchReason(ctx, node) {
|
|
|
921
922
|
function findClonedFromNode(ctx, node) {
|
|
922
923
|
const clonedFromNodeId = readString(node.clonedFromNodeId) || readString(node.cloned_from_node_id);
|
|
923
924
|
if (!clonedFromNodeId) return void 0;
|
|
924
|
-
return ctx.mesh.nodes.find((n) => (0,
|
|
925
|
+
return ctx.mesh.nodes.find((n) => (0, import_daemon_core3.meshNodeIdMatches)(n, clonedFromNodeId));
|
|
925
926
|
}
|
|
926
927
|
function resolvePreferredWorktreeNodeId(ctx) {
|
|
927
928
|
const worktreeNodes = (ctx.mesh.nodes || []).filter((n) => n.isLocalWorktree === true);
|
|
@@ -2316,7 +2317,7 @@ function annotateRapidReadChatAdvisory(payload, options) {
|
|
|
2316
2317
|
}
|
|
2317
2318
|
|
|
2318
2319
|
// src/tools/mesh-tools-internal.ts
|
|
2319
|
-
var
|
|
2320
|
+
var import_daemon_core5 = require("@adhdev/daemon-core");
|
|
2320
2321
|
var import_node_crypto = require("crypto");
|
|
2321
2322
|
var SESSION_PROVIDER_METADATA_TTL_MS = 30 * 6e4;
|
|
2322
2323
|
var meshSessionProviderMetadata = /* @__PURE__ */ new Map();
|
|
@@ -2376,7 +2377,7 @@ function buildDirectTaskPayload(message, via, opts) {
|
|
|
2376
2377
|
};
|
|
2377
2378
|
}
|
|
2378
2379
|
function findNode(mesh, nodeId) {
|
|
2379
|
-
const node = mesh.nodes.find((n) => (0,
|
|
2380
|
+
const node = mesh.nodes.find((n) => (0, import_daemon_core4.meshNodeIdMatches)(n, nodeId));
|
|
2380
2381
|
if (!node) throw new Error(`Node '${nodeId}' is not a member of mesh '${mesh.name}'`);
|
|
2381
2382
|
return node;
|
|
2382
2383
|
}
|
|
@@ -2402,23 +2403,23 @@ async function syncCoordinatorDaemonMeshCache(ctx) {
|
|
|
2402
2403
|
}
|
|
2403
2404
|
}
|
|
2404
2405
|
async function findNodeWithRefresh(ctx, nodeId) {
|
|
2405
|
-
const hit = ctx.mesh.nodes.find((n) => (0,
|
|
2406
|
+
const hit = ctx.mesh.nodes.find((n) => (0, import_daemon_core4.meshNodeIdMatches)(n, nodeId));
|
|
2406
2407
|
if (hit && !hit.isLocalWorktree) return hit;
|
|
2407
2408
|
await refreshMeshFromDaemon(ctx);
|
|
2408
|
-
const refreshed = ctx.mesh.nodes.find((n) => (0,
|
|
2409
|
+
const refreshed = ctx.mesh.nodes.find((n) => (0, import_daemon_core4.meshNodeIdMatches)(n, nodeId));
|
|
2409
2410
|
if (!refreshed) throw new Error(`Node '${nodeId}' is not a member of mesh '${ctx.mesh.name}'`);
|
|
2410
2411
|
return refreshed;
|
|
2411
2412
|
}
|
|
2412
2413
|
async function findOptionalNodeWithRefresh(ctx, nodeId) {
|
|
2413
|
-
const hit = ctx.mesh.nodes.find((n) => (0,
|
|
2414
|
+
const hit = ctx.mesh.nodes.find((n) => (0, import_daemon_core4.meshNodeIdMatches)(n, nodeId));
|
|
2414
2415
|
if (hit && !hit.isLocalWorktree) return hit;
|
|
2415
2416
|
await refreshMeshFromDaemon(ctx);
|
|
2416
|
-
return ctx.mesh.nodes.find((n) => (0,
|
|
2417
|
+
return ctx.mesh.nodes.find((n) => (0, import_daemon_core4.meshNodeIdMatches)(n, nodeId)) ?? null;
|
|
2417
2418
|
}
|
|
2418
2419
|
function hasRecentDuplicateDispatch(ctx, args) {
|
|
2419
2420
|
const now = Date.now();
|
|
2420
2421
|
const normalizedMessage = args.message.trim();
|
|
2421
|
-
for (const task of (0,
|
|
2422
|
+
for (const task of (0, import_daemon_core4.getQueue)(ctx.mesh.id)) {
|
|
2422
2423
|
const timestamp = new Date(task.updatedAt || task.createdAt).getTime();
|
|
2423
2424
|
if (!Number.isFinite(timestamp) || now - timestamp > DUPLICATE_DISPATCH_WINDOW_MS) continue;
|
|
2424
2425
|
if (task.targetNodeId && task.targetNodeId !== args.node_id) continue;
|
|
@@ -2428,7 +2429,7 @@ function hasRecentDuplicateDispatch(ctx, args) {
|
|
|
2428
2429
|
return { duplicate: true, entry: task, source: "queue" };
|
|
2429
2430
|
}
|
|
2430
2431
|
}
|
|
2431
|
-
const entries = (0,
|
|
2432
|
+
const entries = (0, import_daemon_core4.readLedgerEntries)(ctx.mesh.id, { tail: 200 });
|
|
2432
2433
|
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
2433
2434
|
const entry = entries[i];
|
|
2434
2435
|
const timestamp = new Date(entry.timestamp).getTime();
|
|
@@ -2445,7 +2446,7 @@ function hasRecentDuplicateDispatch(ctx, args) {
|
|
|
2445
2446
|
}
|
|
2446
2447
|
function buildMissionInactiveWarning(ctx, missionId) {
|
|
2447
2448
|
if (!missionId) return void 0;
|
|
2448
|
-
const mission = (0,
|
|
2449
|
+
const mission = (0, import_daemon_core4.getMeshMission)(ctx.mesh.id, missionId);
|
|
2449
2450
|
if (!mission || mission.status === "active") return void 0;
|
|
2450
2451
|
const hintByStatus = {
|
|
2451
2452
|
paused: `Mission '${missionId}' (${mission.title}) is paused \u2014 a new task was just attached to it anyway. Mission status is never auto-transitioned; if this mission should be active again, call mesh_mission_upsert(mission_id: '${missionId}', status: 'active').`,
|
|
@@ -2459,7 +2460,7 @@ function buildMissionInactiveWarning(ctx, missionId) {
|
|
|
2459
2460
|
};
|
|
2460
2461
|
}
|
|
2461
2462
|
function buildMissingNodeReadChatRecovery(ctx, args) {
|
|
2462
|
-
const entries = (0,
|
|
2463
|
+
const entries = (0, import_daemon_core4.readLedgerEntries)(ctx.mesh.id, { tail: 300 });
|
|
2463
2464
|
const relatedEntries = entries.filter((entry) => entry.nodeId === args.node_id || entry.sessionId === args.session_id);
|
|
2464
2465
|
const completedEntries = relatedEntries.filter((entry) => entry.kind === "task_completed");
|
|
2465
2466
|
const lastDispatch = [...relatedEntries].reverse().find((entry) => entry.kind === "task_dispatched");
|
|
@@ -2583,7 +2584,7 @@ function readFinalAssistantTranscriptEvidence(payload) {
|
|
|
2583
2584
|
}
|
|
2584
2585
|
function findNodeSession(nodes, nodeId, sessionId) {
|
|
2585
2586
|
if (!nodeId || !sessionId) return {};
|
|
2586
|
-
const node = nodes.find((candidate) => (0,
|
|
2587
|
+
const node = nodes.find((candidate) => (0, import_daemon_core4.meshNodeIdMatches)(candidate, nodeId));
|
|
2587
2588
|
if (!node) return {};
|
|
2588
2589
|
const sessions = Array.isArray(node.sessions) ? node.sessions : [];
|
|
2589
2590
|
const session = sessions.find((candidate) => readSessionRecordId(candidate) === sessionId);
|
|
@@ -2652,10 +2653,10 @@ async function reconcileDirectDispatchesFromTranscriptEvidence(ctx, liveNodes, d
|
|
|
2652
2653
|
});
|
|
2653
2654
|
const payload = unwrapCommandPayload(readResult);
|
|
2654
2655
|
if (payload?.success === false) continue;
|
|
2655
|
-
if ((0,
|
|
2656
|
+
if ((0, import_daemon_core4.hasTrailingToolActivityAfterFinalAssistant)(Array.isArray(payload?.messages) ? payload.messages : [])) continue;
|
|
2656
2657
|
const evidence = readFinalAssistantTranscriptEvidence(payload);
|
|
2657
2658
|
if (!evidence.finalSummary) continue;
|
|
2658
|
-
const result = (0,
|
|
2659
|
+
const result = (0, import_daemon_core4.reconcileDirectDispatchCompletionFromTranscript)({
|
|
2659
2660
|
meshId: ctx.mesh.id,
|
|
2660
2661
|
nodeId,
|
|
2661
2662
|
sessionId,
|
|
@@ -2840,7 +2841,7 @@ function extractLaunchPayload(value) {
|
|
|
2840
2841
|
function classifyMeshLaunchFailure(error) {
|
|
2841
2842
|
const message = error instanceof Error ? error.message : String(error || "launch failed");
|
|
2842
2843
|
const lower = message.toLowerCase();
|
|
2843
|
-
const p2pClassification = (0,
|
|
2844
|
+
const p2pClassification = (0, import_daemon_core4.classifyP2pRelayFailure)(error, { command: "launch_cli" });
|
|
2844
2845
|
if (p2pClassification.recoverable) {
|
|
2845
2846
|
return p2pClassification;
|
|
2846
2847
|
}
|
|
@@ -2915,7 +2916,7 @@ function buildRecoverableLaunchFailure(ctx, node, providerType, error) {
|
|
|
2915
2916
|
function recordRecoverableLaunchFailure(ctx, node, providerType, error) {
|
|
2916
2917
|
const failure = buildRecoverableLaunchFailure(ctx, node, providerType, error);
|
|
2917
2918
|
try {
|
|
2918
|
-
(0,
|
|
2919
|
+
(0, import_daemon_core4.appendLedgerEntry)(ctx.mesh.id, {
|
|
2919
2920
|
kind: "recovery_attempted",
|
|
2920
2921
|
nodeId: node.id,
|
|
2921
2922
|
providerType,
|
|
@@ -2929,7 +2930,7 @@ function recordRecoverableLaunchFailure(ctx, node, providerType, error) {
|
|
|
2929
2930
|
return failure;
|
|
2930
2931
|
}
|
|
2931
2932
|
function getLatestActiveLaunchFailure(meshId, nodeId) {
|
|
2932
|
-
const entries = (0,
|
|
2933
|
+
const entries = (0, import_daemon_core4.readLedgerEntries)(meshId, { tail: 200 });
|
|
2933
2934
|
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
2934
2935
|
const entry = entries[i];
|
|
2935
2936
|
if (entry.nodeId !== nodeId) continue;
|
|
@@ -2941,7 +2942,7 @@ function getLatestActiveLaunchFailure(meshId, nodeId) {
|
|
|
2941
2942
|
return null;
|
|
2942
2943
|
}
|
|
2943
2944
|
function buildCoordinatorP2pRelayFailure(error, context) {
|
|
2944
|
-
const payload = (0,
|
|
2945
|
+
const payload = (0, import_daemon_core4.buildP2pRelayFailurePayload)(error, {
|
|
2945
2946
|
command: context.command,
|
|
2946
2947
|
targetDaemonId: context.targetDaemonId
|
|
2947
2948
|
});
|
|
@@ -3122,7 +3123,7 @@ function rememberMeshSessionProviderMetadataFromEvent(event) {
|
|
|
3122
3123
|
});
|
|
3123
3124
|
}
|
|
3124
3125
|
function resolveMeshSessionProviderMetadataFromLedger(ctx, nodeId, runtimeSessionId) {
|
|
3125
|
-
const entries = (0,
|
|
3126
|
+
const entries = (0, import_daemon_core4.readLedgerEntries)(ctx.mesh.id, { tail: 50 });
|
|
3126
3127
|
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
3127
3128
|
const entry = entries[i];
|
|
3128
3129
|
const payload = entry.payload && typeof entry.payload === "object" && !Array.isArray(entry.payload) ? entry.payload : {};
|
|
@@ -3258,12 +3259,12 @@ function readNodeSupportedProviders(policy) {
|
|
|
3258
3259
|
}
|
|
3259
3260
|
function buildNodeCapabilityExposure(node) {
|
|
3260
3261
|
const providers = readNodeSupportedProviders(node.policy);
|
|
3261
|
-
const capabilityTags = (0,
|
|
3262
|
+
const capabilityTags = (0, import_daemon_core4.buildMeshNodeCapabilityTags)(node);
|
|
3262
3263
|
const exposure = { capabilityTags };
|
|
3263
3264
|
if (providers.length) {
|
|
3264
3265
|
const byProvider = {};
|
|
3265
3266
|
for (const provider of providers) {
|
|
3266
|
-
byProvider[provider] = (0,
|
|
3267
|
+
byProvider[provider] = (0, import_daemon_core4.buildMeshNodeCapabilityTags)(node, provider);
|
|
3267
3268
|
}
|
|
3268
3269
|
exposure.capabilityTagsByProvider = byProvider;
|
|
3269
3270
|
}
|
|
@@ -3572,7 +3573,7 @@ function buildMeshForwardPayloadFromPendingEvent(event) {
|
|
|
3572
3573
|
// eventId (idempotency) and unicast routing intact, matching the reconcile-loop
|
|
3573
3574
|
// relay path (buildForwardPayloadFromPending). Spread LAST so the authoritative
|
|
3574
3575
|
// envelope always wins. Empty for a v1 event (version-skew safe).
|
|
3575
|
-
...(0,
|
|
3576
|
+
...(0, import_daemon_core4.serializeV2EnvelopeToWire)(event)
|
|
3576
3577
|
};
|
|
3577
3578
|
}
|
|
3578
3579
|
async function drainCoordinatorPendingEvents(ctx, opts) {
|
|
@@ -3642,11 +3643,11 @@ async function drainCoordinatorPendingEvents(ctx, opts) {
|
|
|
3642
3643
|
}
|
|
3643
3644
|
return surfacedEvents;
|
|
3644
3645
|
}
|
|
3645
|
-
const drainerIdentity = (0,
|
|
3646
|
+
const drainerIdentity = (0, import_daemon_core4.coordinatorIdentityFromEmitFields)({
|
|
3646
3647
|
daemonId: ctx.localDaemonId,
|
|
3647
3648
|
sessionId: ctx.coordinatorSessionId
|
|
3648
3649
|
});
|
|
3649
|
-
const events = (0,
|
|
3650
|
+
const events = (0, import_daemon_core4.drainPendingMeshCoordinatorEvents)(
|
|
3650
3651
|
ctx.mesh.id,
|
|
3651
3652
|
ctx.localDaemonId,
|
|
3652
3653
|
drainerIdentity ? { drainerIdentity } : void 0
|
|
@@ -3655,7 +3656,7 @@ async function drainCoordinatorPendingEvents(ctx, opts) {
|
|
|
3655
3656
|
return events;
|
|
3656
3657
|
}
|
|
3657
3658
|
function isP2pTransportUnavailableError(error) {
|
|
3658
|
-
return (0,
|
|
3659
|
+
return (0, import_daemon_core4.isP2pRelayTransportFailure)(error);
|
|
3659
3660
|
}
|
|
3660
3661
|
function buildRemoveNodeArgs(ctx, nodeId, sessionCleanupMode, force) {
|
|
3661
3662
|
return {
|
|
@@ -3674,7 +3675,7 @@ function classifyReadChatTransportCause(error) {
|
|
|
3674
3675
|
return "saturated";
|
|
3675
3676
|
}
|
|
3676
3677
|
function resolveCachedMeshSessionPreviewFromLedger(ctx, nodeId, sessionId) {
|
|
3677
|
-
const entries = (0,
|
|
3678
|
+
const entries = (0, import_daemon_core4.readLedgerEntries)(ctx.mesh.id, { tail: 200 });
|
|
3678
3679
|
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
3679
3680
|
const entry = entries[i];
|
|
3680
3681
|
const payload = entry.payload && typeof entry.payload === "object" && !Array.isArray(entry.payload) ? entry.payload : {};
|
|
@@ -3683,7 +3684,7 @@ function resolveCachedMeshSessionPreviewFromLedger(ctx, nodeId, sessionId) {
|
|
|
3683
3684
|
const entrySessionId = readString(entry.sessionId) || readString(payload.targetSessionId) || readString(payload.sessionId) || readString(payload.instanceId);
|
|
3684
3685
|
if (entrySessionId !== sessionId) continue;
|
|
3685
3686
|
const metadataEvent = payload.metadataEvent && typeof payload.metadataEvent === "object" && !Array.isArray(payload.metadataEvent) ? payload.metadataEvent : payload;
|
|
3686
|
-
const preview = (0,
|
|
3687
|
+
const preview = (0, import_daemon_core4.resolveMeshSurfacedSessionPreview)(metadataEvent);
|
|
3687
3688
|
if (preview) {
|
|
3688
3689
|
return { ...preview, ledgerKind: entry.kind, timestamp: entry.timestamp };
|
|
3689
3690
|
}
|
|
@@ -3691,7 +3692,7 @@ function resolveCachedMeshSessionPreviewFromLedger(ctx, nodeId, sessionId) {
|
|
|
3691
3692
|
return void 0;
|
|
3692
3693
|
}
|
|
3693
3694
|
function buildMeshReadChatCacheFallback(ctx, args, node, error) {
|
|
3694
|
-
const classification = (0,
|
|
3695
|
+
const classification = (0, import_daemon_core4.classifyP2pRelayFailure)(error, { command: "read_chat", targetDaemonId: node.daemonId });
|
|
3695
3696
|
const cause = classifyReadChatTransportCause(error);
|
|
3696
3697
|
const errorMessage = error instanceof Error ? error.message : String(error ?? "");
|
|
3697
3698
|
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";
|
|
@@ -3772,12 +3773,12 @@ function summarizePendingEventProtocolMetrics(pendingEvents) {
|
|
|
3772
3773
|
};
|
|
3773
3774
|
}
|
|
3774
3775
|
async function meshStatus(ctx, args = {}) {
|
|
3775
|
-
const rateResult = (0,
|
|
3776
|
+
const rateResult = (0, import_daemon_core5.recordMeshToolCall)({ meshId: ctx.mesh.id, tool: "mesh_status" });
|
|
3776
3777
|
const compact = args.verbose === true ? false : args.compact ?? true;
|
|
3777
3778
|
await refreshMeshFromDaemon(ctx);
|
|
3778
3779
|
const { mesh, transport } = ctx;
|
|
3779
|
-
let ledgerSummary = (0,
|
|
3780
|
-
const schedulingRuntime = (0,
|
|
3780
|
+
let ledgerSummary = (0, import_daemon_core5.getLedgerSummary)(mesh.id);
|
|
3781
|
+
const schedulingRuntime = (0, import_daemon_core5.buildMeshSchedulingRuntime)(mesh, (0, import_daemon_core5.getQueue)(mesh.id));
|
|
3781
3782
|
const schedulingByNode = new Map(schedulingRuntime.nodes.map((n) => [n.nodeId, n]));
|
|
3782
3783
|
const results = await Promise.all(mesh.nodes.map(async (node) => {
|
|
3783
3784
|
const entry = {
|
|
@@ -3841,14 +3842,14 @@ async function meshStatus(ctx, args = {}) {
|
|
|
3841
3842
|
noFallbackReason: failure.noFallbackReason
|
|
3842
3843
|
});
|
|
3843
3844
|
}
|
|
3844
|
-
entry.dataFreshness = (0,
|
|
3845
|
+
entry.dataFreshness = (0, import_daemon_core5.buildMeshNodeProbeFreshness)({
|
|
3845
3846
|
git: entry.git,
|
|
3846
3847
|
liveTruthProbed,
|
|
3847
3848
|
isSelfNode: entry.machine?.sameMachine === true,
|
|
3848
3849
|
daemonId: readNodeDaemonId(node),
|
|
3849
3850
|
node
|
|
3850
3851
|
});
|
|
3851
|
-
const recoveryContext = (0,
|
|
3852
|
+
const recoveryContext = (0, import_daemon_core5.getSessionRecoveryContext)(mesh.id, { nodeId: node.id });
|
|
3852
3853
|
if (recoveryContext.consecutiveNodeFailures > 0) {
|
|
3853
3854
|
entry.recoveryHints = {
|
|
3854
3855
|
consecutiveFailures: recoveryContext.consecutiveNodeFailures,
|
|
@@ -3937,23 +3938,23 @@ async function meshStatus(ctx, args = {}) {
|
|
|
3937
3938
|
}
|
|
3938
3939
|
return entry;
|
|
3939
3940
|
}));
|
|
3940
|
-
let ledgerEntries = (0,
|
|
3941
|
-
let directDispatches = (0,
|
|
3941
|
+
let ledgerEntries = (0, import_daemon_core5.readLedgerEntries)(mesh.id, { tail: 200 });
|
|
3942
|
+
let directDispatches = (0, import_daemon_core5.getActiveDirectDispatches)(mesh.id);
|
|
3942
3943
|
const directReconciliation = await reconcileDirectDispatchesFromTranscriptEvidence(ctx, results, directDispatches, ledgerEntries);
|
|
3943
3944
|
if (directReconciliation.reconciled > 0) {
|
|
3944
|
-
ledgerEntries = (0,
|
|
3945
|
-
directDispatches = (0,
|
|
3946
|
-
ledgerSummary = (0,
|
|
3945
|
+
ledgerEntries = (0, import_daemon_core5.readLedgerEntries)(mesh.id, { tail: 200 });
|
|
3946
|
+
directDispatches = (0, import_daemon_core5.getActiveDirectDispatches)(mesh.id);
|
|
3947
|
+
ledgerSummary = (0, import_daemon_core5.getLedgerSummary)(mesh.id);
|
|
3947
3948
|
}
|
|
3948
|
-
const activeWorkEvidence = (0,
|
|
3949
|
+
const activeWorkEvidence = (0, import_daemon_core5.buildMeshActiveWork)({
|
|
3949
3950
|
meshId: mesh.id,
|
|
3950
|
-
queue: (0,
|
|
3951
|
+
queue: (0, import_daemon_core5.getQueue)(mesh.id),
|
|
3951
3952
|
ledgerEntries,
|
|
3952
3953
|
directDispatches,
|
|
3953
3954
|
nodes: results
|
|
3954
3955
|
});
|
|
3955
3956
|
const pollingGuidance = buildActiveWorkPollingGuidance(activeWorkEvidence.summary);
|
|
3956
|
-
const staleDirectWorkSummary = (0,
|
|
3957
|
+
const staleDirectWorkSummary = (0, import_daemon_core5.buildCompactStaleDirectWorkSummary)(activeWorkEvidence.staleDirectWork, {
|
|
3957
3958
|
note: activeWorkEvidence.staleDirectWorkNote,
|
|
3958
3959
|
detailHint: "Full stale direct entries are omitted from mesh_status by default. Call mesh_status with includeStaleDirectWorkDetails=true or inspect mesh_task_history for ledger detail."
|
|
3959
3960
|
});
|
|
@@ -4178,13 +4179,13 @@ async function meshStatus(ctx, args = {}) {
|
|
|
4178
4179
|
}
|
|
4179
4180
|
if (args.includeUsage === true) {
|
|
4180
4181
|
try {
|
|
4181
|
-
response.usage = (0,
|
|
4182
|
+
response.usage = (0, import_daemon_core5.summarizeMeshUsage)(mesh.id);
|
|
4182
4183
|
} catch {
|
|
4183
4184
|
}
|
|
4184
4185
|
}
|
|
4185
4186
|
try {
|
|
4186
4187
|
if (compact) {
|
|
4187
|
-
const { live, historyFold } = (0,
|
|
4188
|
+
const { live, historyFold } = (0, import_daemon_core5.getMeshStatusMissionsCompact)(mesh.id);
|
|
4188
4189
|
const ranked = [...live].sort((a, b) => String(b.tasks?.lastActivityAt ?? "").localeCompare(String(a.tasks?.lastActivityAt ?? "")));
|
|
4189
4190
|
const kept = [];
|
|
4190
4191
|
const overflow = [];
|
|
@@ -4211,11 +4212,11 @@ async function meshStatus(ctx, args = {}) {
|
|
|
4211
4212
|
}
|
|
4212
4213
|
if (historyFold) response.missionsHistory = historyFold;
|
|
4213
4214
|
} else {
|
|
4214
|
-
const missions = (0,
|
|
4215
|
+
const missions = (0, import_daemon_core5.getMeshStatusMissionSummaries)(mesh.id, { verbose: true });
|
|
4215
4216
|
if (missions.length > 0) {
|
|
4216
4217
|
response.missions = missions.map((mission) => {
|
|
4217
4218
|
try {
|
|
4218
|
-
return { ...mission, stats: (0,
|
|
4219
|
+
return { ...mission, stats: (0, import_daemon_core5.computeMeshMissionStats)(mesh.id, mission.id) };
|
|
4219
4220
|
} catch {
|
|
4220
4221
|
return mission;
|
|
4221
4222
|
}
|
|
@@ -4226,14 +4227,14 @@ async function meshStatus(ctx, args = {}) {
|
|
|
4226
4227
|
}
|
|
4227
4228
|
try {
|
|
4228
4229
|
const pendingEvents = await drainCoordinatorPendingEvents(ctx);
|
|
4229
|
-
const asyncRefineJobs = (0,
|
|
4230
|
+
const asyncRefineJobs = (0, import_daemon_core5.buildMeshAsyncRefineJobs)({
|
|
4230
4231
|
meshId: mesh.id,
|
|
4231
4232
|
ledgerEntries,
|
|
4232
4233
|
pendingEvents
|
|
4233
4234
|
});
|
|
4234
4235
|
if (asyncRefineJobs.length > 0) {
|
|
4235
4236
|
if (compact) {
|
|
4236
|
-
const summary = (0,
|
|
4237
|
+
const summary = (0, import_daemon_core5.summarizeMeshAsyncRefineJobs)(asyncRefineJobs);
|
|
4237
4238
|
if (summary.activeJobs.length > 0) response.asyncRefineJobs = summary.activeJobs;
|
|
4238
4239
|
response.asyncRefineJobsSummary = {
|
|
4239
4240
|
total: summary.total,
|
|
@@ -4244,9 +4245,9 @@ async function meshStatus(ctx, args = {}) {
|
|
|
4244
4245
|
response.asyncRefineJobs = asyncRefineJobs;
|
|
4245
4246
|
}
|
|
4246
4247
|
}
|
|
4247
|
-
const magiActivity = (0,
|
|
4248
|
+
const magiActivity = (0, import_daemon_core5.buildMeshMagiActivity)({ meshId: mesh.id, ledgerEntries });
|
|
4248
4249
|
if (magiActivity.length > 0) {
|
|
4249
|
-
const fold = (0,
|
|
4250
|
+
const fold = (0, import_daemon_core5.summarizeMeshMagiActivity)(magiActivity);
|
|
4250
4251
|
if (compact) {
|
|
4251
4252
|
if (fold.groups.length > 0) response.magiActivity = fold.groups;
|
|
4252
4253
|
response.magiActivitySummary = {
|
|
@@ -4302,12 +4303,12 @@ function normalizeDedupMessage(message) {
|
|
|
4302
4303
|
function findInFlightDuplicate(ctx, message, targetNodeId) {
|
|
4303
4304
|
const fingerprint = normalizeDedupMessage(message);
|
|
4304
4305
|
if (!fingerprint) return null;
|
|
4305
|
-
for (const task of (0,
|
|
4306
|
+
for (const task of (0, import_daemon_core5.getQueue)(ctx.mesh.id)) {
|
|
4306
4307
|
if (task.status !== "pending" && task.status !== "assigned") continue;
|
|
4307
4308
|
if (normalizeDedupMessage(task.message) !== fingerprint) continue;
|
|
4308
4309
|
if (targetNodeId) {
|
|
4309
4310
|
const existingTarget = task.targetNodeId || task.assignedNodeId;
|
|
4310
|
-
if (!existingTarget || !(0,
|
|
4311
|
+
if (!existingTarget || !(0, import_daemon_core5.meshNodeIdMatches)({ id: existingTarget }, targetNodeId)) continue;
|
|
4311
4312
|
}
|
|
4312
4313
|
return { id: task.id, status: task.status, assignedNodeId: task.assignedNodeId, targetNodeId: task.targetNodeId };
|
|
4313
4314
|
}
|
|
@@ -4324,15 +4325,15 @@ async function meshEnqueueTask(ctx, args) {
|
|
|
4324
4325
|
}
|
|
4325
4326
|
const taskMode = readString(args.task_mode) || readString(args.taskMode);
|
|
4326
4327
|
const readonly = args.readonly === true || args.read_only === true;
|
|
4327
|
-
const requiredTags = (0,
|
|
4328
|
+
const requiredTags = (0, import_daemon_core5.normalizeMeshCapabilityTags)(Array.isArray(args.requiredTags) ? args.requiredTags : args.required_tags);
|
|
4328
4329
|
const dependsOn = Array.isArray(args.dependsOn) ? args.dependsOn : Array.isArray(args.depends_on) ? args.depends_on : void 0;
|
|
4329
4330
|
const missionId = readString(args.missionId) || readString(args.mission_id) || void 0;
|
|
4330
|
-
const priority = (0,
|
|
4331
|
+
const priority = (0, import_daemon_core5.normalizeMeshTaskPriority)(readString(args.priority)) || void 0;
|
|
4331
4332
|
const model = readString(args.model) || void 0;
|
|
4332
4333
|
const thinkingLevel = readString(args.thinkingLevel) || void 0;
|
|
4333
4334
|
const difficulty = readString(args.difficulty) || void 0;
|
|
4334
4335
|
const notBeforeRaw = args.notBefore !== void 0 ? args.notBefore : args.not_before;
|
|
4335
|
-
const notBefore = (0,
|
|
4336
|
+
const notBefore = (0, import_daemon_core5.resolveNotBefore)(notBeforeRaw);
|
|
4336
4337
|
const maxRetriesRaw = typeof args.maxRetries === "number" ? args.maxRetries : typeof args.max_retries === "number" ? args.max_retries : void 0;
|
|
4337
4338
|
const maxRetries = typeof maxRetriesRaw === "number" && Number.isFinite(maxRetriesRaw) && maxRetriesRaw >= 0 ? Math.floor(maxRetriesRaw) : void 0;
|
|
4338
4339
|
const allowDuplicate = args.allowDuplicate === true || args.allow_duplicate === true;
|
|
@@ -4341,7 +4342,7 @@ async function meshEnqueueTask(ctx, args) {
|
|
|
4341
4342
|
const preferWorktree = args.preferWorktree === true || args.prefer_worktree === true;
|
|
4342
4343
|
let targetNodeId;
|
|
4343
4344
|
if (explicitTargetRaw) {
|
|
4344
|
-
const matched = ctx.mesh.nodes.find((n) => (0,
|
|
4345
|
+
const matched = ctx.mesh.nodes.find((n) => (0, import_daemon_core5.meshNodeIdMatches)(n, explicitTargetRaw));
|
|
4345
4346
|
if (!matched) {
|
|
4346
4347
|
return JSON.stringify({
|
|
4347
4348
|
success: false,
|
|
@@ -4365,7 +4366,7 @@ async function meshEnqueueTask(ctx, args) {
|
|
|
4365
4366
|
});
|
|
4366
4367
|
}
|
|
4367
4368
|
try {
|
|
4368
|
-
const task = (0,
|
|
4369
|
+
const task = (0, import_daemon_core5.enqueueTask)(ctx.mesh.id, message, {
|
|
4369
4370
|
taskMode,
|
|
4370
4371
|
...readonly ? { readonly: true } : {},
|
|
4371
4372
|
requiredTags,
|
|
@@ -4408,9 +4409,9 @@ async function meshEnqueueTask(ctx, args) {
|
|
|
4408
4409
|
{
|
|
4409
4410
|
const queueTrigger = await triggerMeshQueueAndReport(ctx);
|
|
4410
4411
|
const dependencyStatusById = new Map(
|
|
4411
|
-
(0,
|
|
4412
|
+
(0, import_daemon_core5.getQueue)(ctx.mesh.id).map((t) => [t.id, t.status])
|
|
4412
4413
|
);
|
|
4413
|
-
const eagerPushDeferred = !(0,
|
|
4414
|
+
const eagerPushDeferred = !(0, import_daemon_core5.taskDependenciesSatisfied)(task, dependencyStatusById);
|
|
4414
4415
|
const coordinatorDaemonId = resolveCoordinatorDaemonId(ctx);
|
|
4415
4416
|
const dispatchPromises = [];
|
|
4416
4417
|
const eagerPushTargets = eagerPushDeferred ? [] : ctx.mesh.nodes;
|
|
@@ -4418,7 +4419,7 @@ async function meshEnqueueTask(ctx, args) {
|
|
|
4418
4419
|
const isLocalNode = isLocalControlPlaneNode(ctx, node);
|
|
4419
4420
|
if (isLocalNode || !node.daemonId) continue;
|
|
4420
4421
|
if (targetNodeId && node.id !== targetNodeId) continue;
|
|
4421
|
-
if (!(0,
|
|
4422
|
+
if (!(0, import_daemon_core5.nodeSatisfiesRequiredTags)(requiredTags, (0, import_daemon_core5.buildMeshNodeCapabilityTags)(node))) continue;
|
|
4422
4423
|
dispatchPromises.push(
|
|
4423
4424
|
ipcDispatchToRemoteAgent(ctx, node, {
|
|
4424
4425
|
message,
|
|
@@ -4433,7 +4434,7 @@ async function meshEnqueueTask(ctx, args) {
|
|
|
4433
4434
|
try {
|
|
4434
4435
|
const providerType = result.providerType;
|
|
4435
4436
|
const descriptor = summarizeTaskMessage(message);
|
|
4436
|
-
(0,
|
|
4437
|
+
(0, import_daemon_core5.appendLedgerEntry)(ctx.mesh.id, {
|
|
4437
4438
|
kind: "task_dispatched",
|
|
4438
4439
|
nodeId: node.id,
|
|
4439
4440
|
sessionId: result.sessionId,
|
|
@@ -4455,7 +4456,7 @@ async function meshEnqueueTask(ctx, args) {
|
|
|
4455
4456
|
}
|
|
4456
4457
|
}).catch((err) => {
|
|
4457
4458
|
try {
|
|
4458
|
-
(0,
|
|
4459
|
+
(0, import_daemon_core5.appendLedgerEntry)(ctx.mesh.id, {
|
|
4459
4460
|
kind: "p2p_dispatch_failed",
|
|
4460
4461
|
nodeId: node.id,
|
|
4461
4462
|
payload: {
|
|
@@ -4502,17 +4503,17 @@ async function meshEnqueueTask(ctx, args) {
|
|
|
4502
4503
|
}
|
|
4503
4504
|
}
|
|
4504
4505
|
async function meshViewQueue(ctx, args) {
|
|
4505
|
-
const rateResult = (0,
|
|
4506
|
+
const rateResult = (0, import_daemon_core5.recordMeshToolCall)({ meshId: ctx.mesh.id, tool: "mesh_view_queue" });
|
|
4506
4507
|
const compact = args.verbose === true ? false : args.compact ?? true;
|
|
4507
4508
|
try {
|
|
4508
4509
|
await refreshMeshFromDaemon(ctx);
|
|
4509
4510
|
const statusFilter = sanitizeQueueStatusFilter(args.status);
|
|
4510
4511
|
const view = normalizeQueueViewMode(args.view);
|
|
4511
|
-
const rawQueue = (0,
|
|
4512
|
+
const rawQueue = (0, import_daemon_core5.getQueue)(ctx.mesh.id);
|
|
4512
4513
|
const statusById = new Map(rawQueue.map((task) => [task.id, task.status]));
|
|
4513
4514
|
const withDependencies = rawQueue.map((task) => {
|
|
4514
4515
|
if (!Array.isArray(task.dependsOn) || task.dependsOn.length === 0) return task;
|
|
4515
|
-
const depState = (0,
|
|
4516
|
+
const depState = (0, import_daemon_core5.describeTaskDependencyState)(task, statusById);
|
|
4516
4517
|
return { ...task, ...depState };
|
|
4517
4518
|
});
|
|
4518
4519
|
const liveNodes = await collectMeshViewQueueNodesWithLiveSessionsVerified(ctx);
|
|
@@ -4521,16 +4522,16 @@ async function meshViewQueue(ctx, args) {
|
|
|
4521
4522
|
const summary = buildQueueStatusSummary(fullQueue);
|
|
4522
4523
|
const visibleSummary = buildQueueStatusSummary(queue);
|
|
4523
4524
|
const maintenance = buildQueueMaintenanceReport(fullQueue);
|
|
4524
|
-
let ledgerEntries = (0,
|
|
4525
|
-
let directDispatches = (0,
|
|
4525
|
+
let ledgerEntries = (0, import_daemon_core5.readLedgerEntries)(ctx.mesh.id, { tail: 200 });
|
|
4526
|
+
let directDispatches = (0, import_daemon_core5.getActiveDirectDispatches)(ctx.mesh.id);
|
|
4526
4527
|
const directReconciliation = await reconcileDirectDispatchesFromTranscriptEvidence(ctx, liveNodes, directDispatches, ledgerEntries);
|
|
4527
4528
|
if (directReconciliation.reconciled > 0) {
|
|
4528
|
-
ledgerEntries = (0,
|
|
4529
|
-
directDispatches = (0,
|
|
4529
|
+
ledgerEntries = (0, import_daemon_core5.readLedgerEntries)(ctx.mesh.id, { tail: 200 });
|
|
4530
|
+
directDispatches = (0, import_daemon_core5.getActiveDirectDispatches)(ctx.mesh.id);
|
|
4530
4531
|
}
|
|
4531
|
-
(0,
|
|
4532
|
-
directDispatches = (0,
|
|
4533
|
-
const activeWorkEvidence = (0,
|
|
4532
|
+
(0, import_daemon_core5.markStaleDirectDispatches)(ctx.mesh.id);
|
|
4533
|
+
directDispatches = (0, import_daemon_core5.getActiveDirectDispatches)(ctx.mesh.id);
|
|
4534
|
+
const activeWorkEvidence = (0, import_daemon_core5.buildMeshActiveWork)({
|
|
4534
4535
|
meshId: ctx.mesh.id,
|
|
4535
4536
|
queue: fullQueue,
|
|
4536
4537
|
ledgerEntries,
|
|
@@ -4555,7 +4556,7 @@ async function meshViewQueue(ctx, args) {
|
|
|
4555
4556
|
const wantActiveQueueArray = view === "active" || statusFilter?.some((status) => ACTIVE_QUEUE_STATUSES.has(status));
|
|
4556
4557
|
const wantHistoricalQueueArray = !compact && (view === "historical" || requestedHistoricalRows);
|
|
4557
4558
|
const activeWorkResult = compact ? compactActiveWorkRecords(activeWorkEvidence.activeWork) : { records: activeWorkEvidence.activeWork, omitted: 0 };
|
|
4558
|
-
const staleDirectWorkSummary = (0,
|
|
4559
|
+
const staleDirectWorkSummary = (0, import_daemon_core5.buildCompactStaleDirectWorkSummary)(activeWorkEvidence.staleDirectWork, {
|
|
4559
4560
|
note: activeWorkEvidence.staleDirectWorkNote,
|
|
4560
4561
|
detailHint: "Full stale direct entries are omitted from mesh_view_queue in compact mode. Call mesh_view_queue with verbose=true, or inspect mesh_task_history for ledger detail."
|
|
4561
4562
|
});
|
|
@@ -4630,12 +4631,12 @@ async function meshQueueCancel(ctx, args) {
|
|
|
4630
4631
|
try {
|
|
4631
4632
|
const taskId = (args.task_id || args.taskId || "").trim();
|
|
4632
4633
|
if (!taskId) return JSON.stringify({ success: false, error: "task_id required" });
|
|
4633
|
-
const preCancel = (0,
|
|
4634
|
+
const preCancel = (0, import_daemon_core5.getQueue)(ctx.mesh.id).find((t) => t?.id === taskId);
|
|
4634
4635
|
const wasAssigned = preCancel?.status === "assigned";
|
|
4635
4636
|
const assignedSessionId = readString(preCancel?.assignedSessionId) || void 0;
|
|
4636
4637
|
const assignedNodeId = readString(preCancel?.assignedNodeId) || void 0;
|
|
4637
4638
|
const assignedProviderType = readString(preCancel?.assignedProviderType) || void 0;
|
|
4638
|
-
const task = (0,
|
|
4639
|
+
const task = (0, import_daemon_core5.cancelTask)(ctx.mesh.id, taskId, { reason: args.reason });
|
|
4639
4640
|
if (!task) return JSON.stringify({ success: false, error: `Queue task '${taskId}' not found` });
|
|
4640
4641
|
ctx.transport.command("trigger_mesh_queue", { meshId: ctx.mesh.id }).catch(() => {
|
|
4641
4642
|
});
|
|
@@ -4711,7 +4712,7 @@ async function meshQueueRequeue(ctx, args) {
|
|
|
4711
4712
|
});
|
|
4712
4713
|
return JSON.stringify({ success: true, task: task2 }, null, 2);
|
|
4713
4714
|
}
|
|
4714
|
-
const task = (0,
|
|
4715
|
+
const task = (0, import_daemon_core5.requeueTask)(ctx.mesh.id, taskId, {
|
|
4715
4716
|
reason: args.reason,
|
|
4716
4717
|
targetNodeId,
|
|
4717
4718
|
targetSessionId,
|
|
@@ -4750,17 +4751,17 @@ async function meshTaskHistory(ctx, args) {
|
|
|
4750
4751
|
const compactCap = requestedTail > 50 ? 20 : 30;
|
|
4751
4752
|
const tail = compact ? Math.min(requestedTail, compactCap) : Math.min(requestedTail, 200);
|
|
4752
4753
|
const kind = typeof args.kind === "string" && args.kind.trim() ? [args.kind.trim()] : void 0;
|
|
4753
|
-
const rawEntries = (0,
|
|
4754
|
+
const rawEntries = (0, import_daemon_core5.readLedgerEntries)(mesh.id, { tail, kind });
|
|
4754
4755
|
const entries = compact ? rawEntries.map((e) => ({
|
|
4755
4756
|
...e,
|
|
4756
4757
|
payload: e.payload ? slimLedgerPayload(e.payload) : e.payload
|
|
4757
4758
|
})) : rawEntries;
|
|
4758
|
-
const summary = (0,
|
|
4759
|
+
const summary = (0, import_daemon_core5.getLedgerSummary)(mesh.id);
|
|
4759
4760
|
let taskStats;
|
|
4760
4761
|
try {
|
|
4761
4762
|
const taskIds = [...new Set(rawEntries.map((e) => typeof e.payload?.taskId === "string" ? e.payload.taskId : "").filter(Boolean))];
|
|
4762
4763
|
if (taskIds.length > 0) {
|
|
4763
|
-
const stats = (0,
|
|
4764
|
+
const stats = (0, import_daemon_core5.computeMeshTaskStats)(mesh.id, { taskIds });
|
|
4764
4765
|
if (stats.length > 0) taskStats = stats;
|
|
4765
4766
|
}
|
|
4766
4767
|
} catch {
|
|
@@ -4782,8 +4783,8 @@ async function meshLedgerQuery(ctx, args) {
|
|
|
4782
4783
|
const node = typeof args.node === "string" && args.node.trim() ? args.node.trim() : void 0;
|
|
4783
4784
|
const requestedTail = typeof args.tail === "number" && args.tail > 0 ? Math.floor(args.tail) : 50;
|
|
4784
4785
|
const tail = Math.min(requestedTail, 500);
|
|
4785
|
-
const entries = (0,
|
|
4786
|
-
const summary = (0,
|
|
4786
|
+
const entries = (0, import_daemon_core5.readLedgerEntries)(mesh.id, { tail, kind, since, node });
|
|
4787
|
+
const summary = (0, import_daemon_core5.getLedgerSummary)(mesh.id);
|
|
4787
4788
|
return JSON.stringify({
|
|
4788
4789
|
meshId: mesh.id,
|
|
4789
4790
|
query: {
|
|
@@ -4816,7 +4817,7 @@ async function meshRecordNote(ctx, args) {
|
|
|
4816
4817
|
const supersedes = typeof args.supersedes === "string" && args.supersedes.trim() ? args.supersedes.trim() : void 0;
|
|
4817
4818
|
const subjectKey = typeof args.subject_key === "string" && args.subject_key.trim() ? args.subject_key.trim() : void 0;
|
|
4818
4819
|
const sourceCoordinator = ctx.coordinatorSessionId || ctx.localDaemonId || ctx.coordinatorHostname || void 0;
|
|
4819
|
-
const entry = (0,
|
|
4820
|
+
const entry = (0, import_daemon_core5.appendLedgerEntry)(mesh.id, {
|
|
4820
4821
|
kind: "coordinator_operating_note",
|
|
4821
4822
|
...sourceCoordinator ? { sessionId: sourceCoordinator } : {},
|
|
4822
4823
|
payload: {
|
|
@@ -4854,7 +4855,7 @@ async function meshForgetNote(ctx, args) {
|
|
|
4854
4855
|
return JSON.stringify({ success: false, error: "note_id or text required" }, null, 2);
|
|
4855
4856
|
}
|
|
4856
4857
|
try {
|
|
4857
|
-
const { tombstone, matched } = (0,
|
|
4858
|
+
const { tombstone, matched } = (0, import_daemon_core5.tombstoneOperatingNote)(mesh.id, {
|
|
4858
4859
|
...noteId ? { noteId } : {},
|
|
4859
4860
|
...text ? { text } : {},
|
|
4860
4861
|
...typeof args.reason === "string" && args.reason.trim() ? { reason: args.reason.trim() } : {}
|
|
@@ -4885,8 +4886,8 @@ async function meshReconcileLedger(ctx, args) {
|
|
|
4885
4886
|
const reconcileNode = async (node) => {
|
|
4886
4887
|
try {
|
|
4887
4888
|
if (isLocalControlPlaneNode(ctx, node) || !node.daemonId) {
|
|
4888
|
-
const slice2 = (0,
|
|
4889
|
-
return (0,
|
|
4889
|
+
const slice2 = (0, import_daemon_core5.readLedgerSliceFromStore)(ctx.mesh.id, queryArgs);
|
|
4890
|
+
return (0, import_daemon_core5.buildMeshLedgerReplicaEvidence)({
|
|
4890
4891
|
nodeId: node.id,
|
|
4891
4892
|
daemonId: node.daemonId,
|
|
4892
4893
|
transport: "local",
|
|
@@ -4903,9 +4904,9 @@ async function meshReconcileLedger(ctx, args) {
|
|
|
4903
4904
|
if (slice?.protocol !== "adhdev.mesh.ledger.slice.v1" || !Array.isArray(slice.entries)) {
|
|
4904
4905
|
throw new Error("remote daemon returned an invalid ledger slice payload");
|
|
4905
4906
|
}
|
|
4906
|
-
const importResult = shouldImport ? (0,
|
|
4907
|
+
const importResult = shouldImport ? (0, import_daemon_core5.appendRemoteLedgerEntries)(ctx.mesh.id, slice.entries) : { accepted: 0, skippedDuplicate: 0, rejectedInvalid: 0, entries: [] };
|
|
4907
4908
|
if (shouldImport && importResult.accepted > 0) {
|
|
4908
|
-
(0,
|
|
4909
|
+
(0, import_daemon_core5.appendLedgerEntry)(ctx.mesh.id, {
|
|
4909
4910
|
kind: "ledger_replicated",
|
|
4910
4911
|
nodeId: node.id,
|
|
4911
4912
|
payload: {
|
|
@@ -4918,7 +4919,7 @@ async function meshReconcileLedger(ctx, args) {
|
|
|
4918
4919
|
}
|
|
4919
4920
|
});
|
|
4920
4921
|
}
|
|
4921
|
-
return (0,
|
|
4922
|
+
return (0, import_daemon_core5.buildMeshLedgerReplicaEvidence)({
|
|
4922
4923
|
nodeId: node.id,
|
|
4923
4924
|
daemonId: node.daemonId,
|
|
4924
4925
|
transport: "p2p_datachannel",
|
|
@@ -4926,7 +4927,7 @@ async function meshReconcileLedger(ctx, args) {
|
|
|
4926
4927
|
importResult
|
|
4927
4928
|
});
|
|
4928
4929
|
} catch (e) {
|
|
4929
|
-
return (0,
|
|
4930
|
+
return (0, import_daemon_core5.buildMeshLedgerReplicaEvidence)({
|
|
4930
4931
|
nodeId: node.id,
|
|
4931
4932
|
daemonId: node.daemonId,
|
|
4932
4933
|
transport: node.daemonId ? "p2p_datachannel" : "local",
|
|
@@ -4941,7 +4942,7 @@ async function meshReconcileLedger(ctx, args) {
|
|
|
4941
4942
|
replicas.push(outcome.value);
|
|
4942
4943
|
} else {
|
|
4943
4944
|
const node = nodes[idx];
|
|
4944
|
-
replicas.push((0,
|
|
4945
|
+
replicas.push((0, import_daemon_core5.buildMeshLedgerReplicaEvidence)({
|
|
4945
4946
|
nodeId: node.id,
|
|
4946
4947
|
daemonId: node.daemonId,
|
|
4947
4948
|
transport: node.daemonId ? "p2p_datachannel" : "local",
|
|
@@ -4950,8 +4951,8 @@ async function meshReconcileLedger(ctx, args) {
|
|
|
4950
4951
|
}));
|
|
4951
4952
|
}
|
|
4952
4953
|
});
|
|
4953
|
-
const evidence = (0,
|
|
4954
|
-
(0,
|
|
4954
|
+
const evidence = (0, import_daemon_core5.buildMeshLedgerReconciliationEvidence)(ctx.mesh.id, replicas);
|
|
4955
|
+
(0, import_daemon_core5.appendLedgerEntry)(ctx.mesh.id, {
|
|
4955
4956
|
kind: "ledger_reconciled",
|
|
4956
4957
|
payload: {
|
|
4957
4958
|
protocol: evidence.protocol,
|
|
@@ -4972,7 +4973,7 @@ async function meshRequeueHeldEvents(ctx, args) {
|
|
|
4972
4973
|
...readString(raw.reason) ? { reason: readString(raw.reason) } : {},
|
|
4973
4974
|
...readString(raw.since) ? { since: readString(raw.since) } : {}
|
|
4974
4975
|
} : void 0;
|
|
4975
|
-
const result = (0,
|
|
4976
|
+
const result = (0, import_daemon_core5.requeueHeldMeshCoordinatorEvents)(mesh.id, filter && Object.keys(filter).length > 0 ? filter : void 0);
|
|
4976
4977
|
const note = result.matched === 0 ? "No recoverable held events matched. Nothing to requeue." : `${result.requeued} held event(s) restored to the pending queue` + (result.dedupSuppressed > 0 ? ` (${result.dedupSuppressed} collapsed onto still-live duplicates)` : "") + (result.alreadyRequeued > 0 ? `; ${result.alreadyRequeued} already recovered by a prior pass` : "") + (result.unrecoverable > 0 ? `; ${result.unrecoverable} had no restorable original event` : "") + ". A coordinator will drain them on its next poll.";
|
|
4977
4978
|
return JSON.stringify({ success: true, ...result, note }, null, 2);
|
|
4978
4979
|
}
|
|
@@ -4990,7 +4991,7 @@ async function meshMissionUpsert(ctx, args) {
|
|
|
4990
4991
|
error: "mission_title_required: single-mission upsert needs a non-empty title. For a bulk status transition pass mission_ids (array) + status instead."
|
|
4991
4992
|
});
|
|
4992
4993
|
}
|
|
4993
|
-
const mission = (0,
|
|
4994
|
+
const mission = (0, import_daemon_core5.upsertMeshMission)(ctx.mesh.id, {
|
|
4994
4995
|
id: readString(args.mission_id) || readString(args.missionId) || void 0,
|
|
4995
4996
|
title,
|
|
4996
4997
|
goal: typeof args.goal === "string" ? args.goal : void 0,
|
|
@@ -5026,9 +5027,9 @@ async function meshMissionUpsertBulk(ctx, missionIds, status) {
|
|
|
5026
5027
|
}
|
|
5027
5028
|
const results = missionIds.map((id) => {
|
|
5028
5029
|
try {
|
|
5029
|
-
const existing = (0,
|
|
5030
|
+
const existing = (0, import_daemon_core5.getMeshMission)(ctx.mesh.id, id);
|
|
5030
5031
|
if (!existing) return { id, ok: false, error: "mission_not_found" };
|
|
5031
|
-
const updated = (0,
|
|
5032
|
+
const updated = (0, import_daemon_core5.upsertMeshMission)(ctx.mesh.id, {
|
|
5032
5033
|
id,
|
|
5033
5034
|
title: existing.title,
|
|
5034
5035
|
status
|
|
@@ -5055,12 +5056,12 @@ async function meshMissionUpsertBulk(ctx, missionIds, status) {
|
|
|
5055
5056
|
async function meshMissionList(ctx, args = {}) {
|
|
5056
5057
|
try {
|
|
5057
5058
|
const rawStatuses = Array.isArray(args.status) ? args.status : typeof args.status === "string" && args.status.trim() ? [args.status] : [];
|
|
5058
|
-
const invalid = rawStatuses.filter((s) => !
|
|
5059
|
+
const invalid = rawStatuses.filter((s) => !import_daemon_core5.MESH_MISSION_STATUSES.includes(s));
|
|
5059
5060
|
if (invalid.length > 0) {
|
|
5060
5061
|
return JSON.stringify({
|
|
5061
5062
|
success: false,
|
|
5062
5063
|
code: "invalid_mission_status",
|
|
5063
|
-
error: `invalid status filter: ${invalid.join(", ")} (valid: ${
|
|
5064
|
+
error: `invalid status filter: ${invalid.join(", ")} (valid: ${import_daemon_core5.MESH_MISSION_STATUSES.join(", ")})`
|
|
5064
5065
|
});
|
|
5065
5066
|
}
|
|
5066
5067
|
const statuses = rawStatuses.length > 0 ? rawStatuses : void 0;
|
|
@@ -5068,7 +5069,7 @@ async function meshMissionList(ctx, args = {}) {
|
|
|
5068
5069
|
const verbose = args.verbose === true;
|
|
5069
5070
|
const withStats = verbose || (args.include_stats ?? args.includeStats) === true;
|
|
5070
5071
|
const limit = typeof args.limit === "number" && Number.isFinite(args.limit) && args.limit > 0 ? Math.floor(args.limit) : void 0;
|
|
5071
|
-
const result = (0,
|
|
5072
|
+
const result = (0, import_daemon_core5.listMeshMissionsForTool)(ctx.mesh.id, {
|
|
5072
5073
|
statuses,
|
|
5073
5074
|
verbose,
|
|
5074
5075
|
includeMagi,
|
|
@@ -5101,7 +5102,7 @@ async function meshReviewInbox(ctx, args = {}) {
|
|
|
5101
5102
|
}
|
|
5102
5103
|
|
|
5103
5104
|
// src/tools/mesh-tools-magi.ts
|
|
5104
|
-
var
|
|
5105
|
+
var import_daemon_core6 = require("@adhdev/daemon-core");
|
|
5105
5106
|
var MAGI_MAX_REPLICAS = 12;
|
|
5106
5107
|
var MAGI_MIN_TARGETS = 2;
|
|
5107
5108
|
var MAGI_CLUSTER_JACCARD = 0.4;
|
|
@@ -5585,19 +5586,19 @@ function buildMagiFanoutPlan(slots, nodes, opts = {}) {
|
|
|
5585
5586
|
slotList.forEach((slot, slotIndex) => {
|
|
5586
5587
|
const provider = slot.provider;
|
|
5587
5588
|
const model = typeof slot.model === "string" && slot.model.trim() ? slot.model.trim() : void 0;
|
|
5588
|
-
const capabilityTags = (0,
|
|
5589
|
-
const requiredTags = (0,
|
|
5589
|
+
const capabilityTags = (0, import_daemon_core5.normalizeMeshCapabilityTags)(slot.capabilityTags);
|
|
5590
|
+
const requiredTags = (0, import_daemon_core5.normalizeMeshCapabilityTags)([`provider=${provider}`, ...capabilityTags]);
|
|
5590
5591
|
const count = replicaCountFor(slot, defaultN, opts.n);
|
|
5591
5592
|
let targetNodeId;
|
|
5592
5593
|
let candidateNodes = [];
|
|
5593
5594
|
if (slot.nodeId) {
|
|
5594
|
-
const node = nodes.find((n) => (0,
|
|
5595
|
+
const node = nodes.find((n) => (0, import_daemon_core5.meshNodeIdMatches)(n, slot.nodeId));
|
|
5595
5596
|
if (node) {
|
|
5596
5597
|
targetNodeId = node.id;
|
|
5597
5598
|
candidateNodes = [node];
|
|
5598
5599
|
}
|
|
5599
5600
|
} else {
|
|
5600
|
-
candidateNodes = nodes.filter((n) => (0,
|
|
5601
|
+
candidateNodes = nodes.filter((n) => (0, import_daemon_core5.nodeSatisfiesRequiredTags)(requiredTags, (0, import_daemon_core5.buildMeshNodeCapabilityTags)(n)));
|
|
5601
5602
|
}
|
|
5602
5603
|
const available = candidateNodes.length > 0;
|
|
5603
5604
|
if (!available) {
|
|
@@ -5611,9 +5612,9 @@ function buildMagiFanoutPlan(slots, nodes, opts = {}) {
|
|
|
5611
5612
|
slotResolutions.push({ slotIndex, provider, nodeId: slot.nodeId, capabilityTags, available: false, gitStale: false, unhealthy: false, excluded: true, reason: "unavailable" });
|
|
5612
5613
|
return;
|
|
5613
5614
|
}
|
|
5614
|
-
const launchableCandidates = candidateNodes.filter((n) => (0,
|
|
5615
|
+
const launchableCandidates = candidateNodes.filter((n) => (0, import_daemon_core5.isMeshNodeHealthLaunchable)(n));
|
|
5615
5616
|
if (launchableCandidates.length === 0) {
|
|
5616
|
-
const health = (0,
|
|
5617
|
+
const health = (0, import_daemon_core5.resolveEffectiveMeshNodeHealth)(candidateNodes[0]);
|
|
5617
5618
|
unhealthySlots.push({
|
|
5618
5619
|
slotIndex,
|
|
5619
5620
|
provider,
|
|
@@ -5678,7 +5679,7 @@ function buildMagiFanoutPlan(slots, nodes, opts = {}) {
|
|
|
5678
5679
|
// Candidate pool was already narrowed to launch-ready nodes above, so an
|
|
5679
5680
|
// included slot is health-launchable by construction.
|
|
5680
5681
|
unhealthy: false,
|
|
5681
|
-
health: (0,
|
|
5682
|
+
health: (0, import_daemon_core5.resolveEffectiveMeshNodeHealth)(candidateNodes[0]),
|
|
5682
5683
|
excluded: false
|
|
5683
5684
|
};
|
|
5684
5685
|
if (gitStale && !includeStale) {
|
|
@@ -5851,13 +5852,13 @@ function collectMagiCandidateTexts(payload) {
|
|
|
5851
5852
|
}
|
|
5852
5853
|
function replicaCompletionIsWeak(meshId, taskId) {
|
|
5853
5854
|
try {
|
|
5854
|
-
const entries = (0,
|
|
5855
|
+
const entries = (0, import_daemon_core5.readLedgerEntries)(meshId, { kind: ["task_completed"], tail: 200 });
|
|
5855
5856
|
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
5856
5857
|
const entry = entries[i];
|
|
5857
5858
|
const payload = entry?.payload && typeof entry.payload === "object" ? entry.payload : void 0;
|
|
5858
5859
|
const entryTaskId = readString(payload?.taskId) || readString(entry?.taskId);
|
|
5859
5860
|
if (!entryTaskId || entryTaskId !== taskId) continue;
|
|
5860
|
-
if ((0,
|
|
5861
|
+
if ((0, import_daemon_core5.isWeakCompletionEvidence)(payload)) return true;
|
|
5861
5862
|
const diag = payload?.completionDiagnostic;
|
|
5862
5863
|
if (diag && typeof diag === "object" && !Array.isArray(diag) && readString(diag.reason) === "short_generating_suppressed") {
|
|
5863
5864
|
return true;
|
|
@@ -5884,9 +5885,9 @@ async function meshMagiKindPanelSet(ctx, args) {
|
|
|
5884
5885
|
const meshId = ctx.mesh.id;
|
|
5885
5886
|
const scope = magiPanelScope(meshId, ctx.mesh.name);
|
|
5886
5887
|
try {
|
|
5887
|
-
const current = (0,
|
|
5888
|
+
const current = (0, import_daemon_core5.getMagiKindPanel)(kind, meshId) ?? [];
|
|
5888
5889
|
if (!write) {
|
|
5889
|
-
const preview = (0,
|
|
5890
|
+
const preview = (0, import_daemon_core5.normalizeMagiSlots)(args.slots, ctx.mesh.nodes.map((n) => n.id));
|
|
5890
5891
|
return JSON.stringify({
|
|
5891
5892
|
success: true,
|
|
5892
5893
|
dryRun: true,
|
|
@@ -5898,7 +5899,7 @@ async function meshMagiKindPanelSet(ctx, args) {
|
|
|
5898
5899
|
note: `Dry-run only \u2014 no file written. This is a WHOLESALE replacement of the kind's slot list for mesh '${meshId}' (machine-local ~/.adhdev/meshes.json); the currentSlots would be fully replaced. Other meshes on this machine are unaffected. Re-run with write=true after explicit user approval.`
|
|
5899
5900
|
}, null, 2);
|
|
5900
5901
|
}
|
|
5901
|
-
const slots = (0,
|
|
5902
|
+
const slots = (0, import_daemon_core5.setMagiKindPanel)(kind, args.slots, meshId);
|
|
5902
5903
|
return JSON.stringify({
|
|
5903
5904
|
success: true,
|
|
5904
5905
|
written: true,
|
|
@@ -5919,9 +5920,9 @@ async function meshMagiKindPanelList(ctx, args = {}) {
|
|
|
5919
5920
|
const only = readString(args.task_kind) || readString(args.kind);
|
|
5920
5921
|
const meshId = ctx.mesh.id;
|
|
5921
5922
|
const scope = magiPanelScope(meshId, ctx.mesh.name);
|
|
5922
|
-
const all = (0,
|
|
5923
|
+
const all = (0, import_daemon_core5.listMagiKindPanels)(meshId);
|
|
5923
5924
|
if (only) {
|
|
5924
|
-
const slots = (0,
|
|
5925
|
+
const slots = (0, import_daemon_core5.getMagiKindPanel)(only, meshId);
|
|
5925
5926
|
if (slots === void 0) {
|
|
5926
5927
|
return JSON.stringify({
|
|
5927
5928
|
success: false,
|
|
@@ -5954,7 +5955,7 @@ async function meshMagiReview(ctx, args) {
|
|
|
5954
5955
|
const referenceSubmoduleKey = resolveMagiReferenceSubmoduleKey(ctx);
|
|
5955
5956
|
const taskKind = normalizeMagiTaskKind(explicitTaskKind);
|
|
5956
5957
|
const panelName = `(kind:${taskKind})`;
|
|
5957
|
-
const slots = (0,
|
|
5958
|
+
const slots = (0, import_daemon_core5.getMagiKindPanel)(taskKind, ctx.mesh.id);
|
|
5958
5959
|
if (!slots || slots.length === 0) {
|
|
5959
5960
|
return JSON.stringify({
|
|
5960
5961
|
success: false,
|
|
@@ -5962,13 +5963,13 @@ async function meshMagiReview(ctx, args) {
|
|
|
5962
5963
|
error: `No panel slots are configured for this task_kind in mesh '${ctx.mesh.id}' settings. Add at least one (machine + provider + model) slot in settings \u2014 task_kind '${taskKind}' has no configured kind-panel.`,
|
|
5963
5964
|
taskKind,
|
|
5964
5965
|
meshId: ctx.mesh.id,
|
|
5965
|
-
configuredKinds: Object.keys((0,
|
|
5966
|
+
configuredKinds: Object.keys((0, import_daemon_core5.listMagiKindPanels)(ctx.mesh.id)),
|
|
5966
5967
|
hint: "Configure this kind in mesh settings (MagiKindPanelEditor), or set it with mesh_magi_kind_panel_set, then retry."
|
|
5967
5968
|
}, null, 2);
|
|
5968
5969
|
}
|
|
5969
5970
|
let planSlots;
|
|
5970
5971
|
try {
|
|
5971
|
-
planSlots = (0,
|
|
5972
|
+
planSlots = (0, import_daemon_core5.normalizeMagiSlots)(slots);
|
|
5972
5973
|
} catch (e) {
|
|
5973
5974
|
return JSON.stringify({
|
|
5974
5975
|
success: false,
|
|
@@ -6024,7 +6025,7 @@ async function meshMagiReview(ctx, args) {
|
|
|
6024
6025
|
const waitTimeoutMs = Math.min(MAGI_MAX_WAIT_MS, Math.max(MAGI_POLL_INTERVAL_MS, Number(args.wait_timeout_ms ?? args.waitTimeoutMs) || MAGI_DEFAULT_WAIT_MS));
|
|
6025
6026
|
const consensusGroupId = `magi_${(0, import_node_crypto.randomUUID)().replace(/-/g, "")}`;
|
|
6026
6027
|
const titleQ = question.length > 80 ? `${question.slice(0, 77)}...` : question;
|
|
6027
|
-
const mission = (0,
|
|
6028
|
+
const mission = (0, import_daemon_core5.upsertMeshMission)(ctx.mesh.id, {
|
|
6028
6029
|
title: `MAGI: ${titleQ}`,
|
|
6029
6030
|
goal: `Cross-verify (read-only) across panel '${panelName}': ${question}${args.target ? `
|
|
6030
6031
|
Target: ${args.target}` : ""}`,
|
|
@@ -6036,7 +6037,7 @@ Target: ${args.target}` : ""}`,
|
|
|
6036
6037
|
const replicaRecords = [];
|
|
6037
6038
|
for (const replica of plan.replicas) {
|
|
6038
6039
|
try {
|
|
6039
|
-
const task = (0,
|
|
6040
|
+
const task = (0, import_daemon_core5.enqueueTask)(ctx.mesh.id, prompt, {
|
|
6040
6041
|
readonly: true,
|
|
6041
6042
|
taskMode: "live_debug_readonly",
|
|
6042
6043
|
requiredTags: replica.requiredTags,
|
|
@@ -6049,7 +6050,7 @@ Target: ${args.target}` : ""}`,
|
|
|
6049
6050
|
replicaRecords.push({ taskId: task.id, provider: replica.provider, targetNodeId: replica.targetNodeId, requiredTags: replica.requiredTags });
|
|
6050
6051
|
} catch (e) {
|
|
6051
6052
|
try {
|
|
6052
|
-
(0,
|
|
6053
|
+
(0, import_daemon_core5.appendLedgerEntry)(ctx.mesh.id, {
|
|
6053
6054
|
kind: "magi_replica_enqueue_failed",
|
|
6054
6055
|
payload: { consensusGroupId, missionId: mission.id, provider: replica.provider, error: e?.message || String(e) }
|
|
6055
6056
|
});
|
|
@@ -6139,7 +6140,7 @@ Target: ${args.target}` : ""}`,
|
|
|
6139
6140
|
});
|
|
6140
6141
|
closeMagiMissionIfTerminal(ctx, mission.id, collected.terminal);
|
|
6141
6142
|
const cleanupMode = resolveMagiAutoCleanupMode(ctx, args.auto_cleanup ?? args.autoCleanup);
|
|
6142
|
-
const cleanupReplicaTasks = findMagiReplicaTasks((0,
|
|
6143
|
+
const cleanupReplicaTasks = findMagiReplicaTasks((0, import_daemon_core5.getQueue)(ctx.mesh.id), consensusGroupId);
|
|
6143
6144
|
const cleanup = await cleanupMagiAutoLaunchedSessions(ctx, {
|
|
6144
6145
|
replicaTasks: cleanupReplicaTasks,
|
|
6145
6146
|
terminal: collected.terminal,
|
|
@@ -6169,7 +6170,7 @@ async function meshMagiCollect(ctx, args) {
|
|
|
6169
6170
|
await refreshMeshFromDaemon(ctx);
|
|
6170
6171
|
const explicitKind = args.task_kind ?? args.taskKind;
|
|
6171
6172
|
const taskKind = explicitKind !== void 0 ? normalizeMagiTaskKind(explicitKind) : recoverMagiTaskKind(ctx, consensusGroupId);
|
|
6172
|
-
const replicaTasks = findMagiReplicaTasks((0,
|
|
6173
|
+
const replicaTasks = findMagiReplicaTasks((0, import_daemon_core5.getQueue)(ctx.mesh.id), consensusGroupId);
|
|
6173
6174
|
if (replicaTasks.length === 0) {
|
|
6174
6175
|
return JSON.stringify({
|
|
6175
6176
|
success: false,
|
|
@@ -6273,7 +6274,7 @@ function computeMagiCleanupTargets(replicaTasks) {
|
|
|
6273
6274
|
function resolveMagiAutoCleanupMode(ctx, perCallOverride) {
|
|
6274
6275
|
if (perCallOverride === true) return "stop_and_delete";
|
|
6275
6276
|
if (perCallOverride === false) return "preserve";
|
|
6276
|
-
return (0,
|
|
6277
|
+
return (0, import_daemon_core6.resolveMagiSessionCleanupMode)(ctx.mesh?.policy?.magiSessionCleanup);
|
|
6277
6278
|
}
|
|
6278
6279
|
async function cleanupMagiAutoLaunchedSessions(ctx, args) {
|
|
6279
6280
|
if (args.mode === "preserve") return null;
|
|
@@ -6352,7 +6353,7 @@ function classifyStaleReplicas(annotatedTasks, terminal = MAGI_TERMINAL_STATUSES
|
|
|
6352
6353
|
}
|
|
6353
6354
|
function persistMagiDispatched(ctx, args) {
|
|
6354
6355
|
try {
|
|
6355
|
-
(0,
|
|
6356
|
+
(0, import_daemon_core5.appendLedgerEntry)(ctx.mesh.id, {
|
|
6356
6357
|
kind: "magi_dispatched",
|
|
6357
6358
|
payload: {
|
|
6358
6359
|
source: "magi",
|
|
@@ -6372,7 +6373,7 @@ function persistMagiDispatched(ctx, args) {
|
|
|
6372
6373
|
}
|
|
6373
6374
|
function recoverMagiTaskKind(ctx, consensusGroupId) {
|
|
6374
6375
|
try {
|
|
6375
|
-
const entries = (0,
|
|
6376
|
+
const entries = (0, import_daemon_core5.readLedgerEntries)(ctx.mesh.id, { kind: ["magi_dispatched"], tail: 200 });
|
|
6376
6377
|
for (let i = entries.length - 1; i >= 0; i -= 1) {
|
|
6377
6378
|
const payload = entries[i]?.payload;
|
|
6378
6379
|
if (!payload || typeof payload !== "object") continue;
|
|
@@ -6396,7 +6397,7 @@ function stripRawAnswers(synthesis) {
|
|
|
6396
6397
|
}
|
|
6397
6398
|
function persistMagiSynthesis(ctx, args) {
|
|
6398
6399
|
try {
|
|
6399
|
-
(0,
|
|
6400
|
+
(0, import_daemon_core5.appendLedgerEntry)(ctx.mesh.id, {
|
|
6400
6401
|
kind: "magi_synthesis",
|
|
6401
6402
|
payload: {
|
|
6402
6403
|
source: "magi",
|
|
@@ -6416,9 +6417,9 @@ function closeMagiMissionIfTerminal(ctx, missionId, terminal) {
|
|
|
6416
6417
|
const id = readString(missionId);
|
|
6417
6418
|
if (!id) return;
|
|
6418
6419
|
try {
|
|
6419
|
-
const mission = (0,
|
|
6420
|
+
const mission = (0, import_daemon_core5.getMeshMission)(ctx.mesh.id, id);
|
|
6420
6421
|
if (!mission || mission.status !== "active") return;
|
|
6421
|
-
(0,
|
|
6422
|
+
(0, import_daemon_core5.upsertMeshMission)(ctx.mesh.id, {
|
|
6422
6423
|
id,
|
|
6423
6424
|
title: mission.title,
|
|
6424
6425
|
// Preserve goal: upsert defaults goal to the existing value when omitted.
|
|
@@ -6453,8 +6454,8 @@ async function collectMagiResponses(ctx, args) {
|
|
|
6453
6454
|
const candidates = collectMagiCandidateTexts(payload);
|
|
6454
6455
|
const raw = candidates.find((c) => c.trim().length > 0);
|
|
6455
6456
|
if (!raw) return;
|
|
6456
|
-
if (raw.length >
|
|
6457
|
-
source.rawAnswer = raw.slice(0,
|
|
6457
|
+
if (raw.length > import_daemon_core5.MAGI_RAW_ANSWER_CAP) {
|
|
6458
|
+
source.rawAnswer = raw.slice(0, import_daemon_core5.MAGI_RAW_ANSWER_CAP);
|
|
6458
6459
|
source.rawAnswerTruncated = true;
|
|
6459
6460
|
} else {
|
|
6460
6461
|
source.rawAnswer = raw;
|
|
@@ -6464,7 +6465,7 @@ async function collectMagiResponses(ctx, args) {
|
|
|
6464
6465
|
};
|
|
6465
6466
|
const buildSource = (task) => {
|
|
6466
6467
|
const sourceNodeId = task.assignedNodeId || task.targetNodeId || void 0;
|
|
6467
|
-
const gitRef = extractNodeGitRef(sourceNodeId ? ctx.mesh.nodes.find((n) => (0,
|
|
6468
|
+
const gitRef = extractNodeGitRef(sourceNodeId ? ctx.mesh.nodes.find((n) => (0, import_daemon_core5.meshNodeIdMatches)(n, sourceNodeId)) : void 0);
|
|
6468
6469
|
return {
|
|
6469
6470
|
taskId: task.id,
|
|
6470
6471
|
nodeId: sourceNodeId,
|
|
@@ -6474,7 +6475,7 @@ async function collectMagiResponses(ctx, args) {
|
|
|
6474
6475
|
};
|
|
6475
6476
|
};
|
|
6476
6477
|
const sendKindRetry = async (task, failReason) => {
|
|
6477
|
-
const node = ctx.mesh.nodes.find((n) => (0,
|
|
6478
|
+
const node = ctx.mesh.nodes.find((n) => (0, import_daemon_core5.meshNodeIdMatches)(n, task.assignedNodeId));
|
|
6478
6479
|
if (!node || !task.assignedSessionId) return false;
|
|
6479
6480
|
const why = failReason === "empty_evidence" ? "your previous answer had an empty evidence array" : failReason === "missing_required_fields" ? "your previous answer was missing required fields" : "your previous answer did not parse as the required JSON";
|
|
6480
6481
|
const message = `Your previous MAGI answer could not be accepted (${why}). Respond NOW with ONLY a single JSON object (no prose, no code fence) matching EXACTLY this schema, with non-empty evidence:
|
|
@@ -6498,7 +6499,7 @@ ${magiOutputContractFor(kind)}`;
|
|
|
6498
6499
|
}
|
|
6499
6500
|
});
|
|
6500
6501
|
try {
|
|
6501
|
-
(0,
|
|
6502
|
+
(0, import_daemon_core5.appendLedgerEntry)(ctx.mesh.id, {
|
|
6502
6503
|
kind: "magi_replica_retry",
|
|
6503
6504
|
payload: { taskId: task.id, kind, failReason }
|
|
6504
6505
|
});
|
|
@@ -6510,7 +6511,7 @@ ${magiOutputContractFor(kind)}`;
|
|
|
6510
6511
|
}
|
|
6511
6512
|
};
|
|
6512
6513
|
const nudgeWedgedReplica = async (task) => {
|
|
6513
|
-
const node = ctx.mesh.nodes.find((n) => (0,
|
|
6514
|
+
const node = ctx.mesh.nodes.find((n) => (0, import_daemon_core5.meshNodeIdMatches)(n, task.assignedNodeId));
|
|
6514
6515
|
if (!node || !task.assignedSessionId) return;
|
|
6515
6516
|
try {
|
|
6516
6517
|
const read = await commandForNode(ctx, node, "read_chat", {
|
|
@@ -6532,7 +6533,7 @@ ${magiOutputContractFor(kind)}`;
|
|
|
6532
6533
|
action: "approve"
|
|
6533
6534
|
});
|
|
6534
6535
|
try {
|
|
6535
|
-
(0,
|
|
6536
|
+
(0, import_daemon_core5.appendLedgerEntry)(ctx.mesh.id, {
|
|
6536
6537
|
kind: "magi_replica_auto_approved",
|
|
6537
6538
|
payload: { taskId: task.id, nodeId: task.assignedNodeId, status }
|
|
6538
6539
|
});
|
|
@@ -6576,7 +6577,7 @@ ${magiOutputContractFor(kind)}`;
|
|
|
6576
6577
|
}
|
|
6577
6578
|
let kindResult;
|
|
6578
6579
|
try {
|
|
6579
|
-
const node = ctx.mesh.nodes.find((n) => (0,
|
|
6580
|
+
const node = ctx.mesh.nodes.find((n) => (0, import_daemon_core5.meshNodeIdMatches)(n, task.assignedNodeId));
|
|
6580
6581
|
if (!node) throw new Error("assigned node not in mesh");
|
|
6581
6582
|
const result = await commandForNode(ctx, node, "read_chat", {
|
|
6582
6583
|
sessionId: task.assignedSessionId,
|
|
@@ -6629,7 +6630,7 @@ ${magiOutputContractFor(kind)}`;
|
|
|
6629
6630
|
return false;
|
|
6630
6631
|
};
|
|
6631
6632
|
for (; ; ) {
|
|
6632
|
-
const tasks = annotateQueueStaleness((0,
|
|
6633
|
+
const tasks = annotateQueueStaleness((0, import_daemon_core5.getQueue)(ctx.mesh.id).filter((t) => ids.has(t.id)), ctx.mesh);
|
|
6633
6634
|
const allPresent = tasks.length === ids.size;
|
|
6634
6635
|
const { staleTaskIds: staleTaskIds2, staleReasons: staleReasons2 } = classifyStaleReplicas(tasks, TERMINAL);
|
|
6635
6636
|
const pastDeadline = Date.now() >= deadline;
|
|
@@ -6643,7 +6644,7 @@ ${magiOutputContractFor(kind)}`;
|
|
|
6643
6644
|
if (allPresent && outstanding.length > 0 && outstanding.every((t) => staleTaskIds2.has(t.id))) break;
|
|
6644
6645
|
await sleep(Math.min(MAGI_POLL_INTERVAL_MS, Math.max(0, deadline - Date.now())));
|
|
6645
6646
|
}
|
|
6646
|
-
const finalTasks = annotateQueueStaleness((0,
|
|
6647
|
+
const finalTasks = annotateQueueStaleness((0, import_daemon_core5.getQueue)(ctx.mesh.id).filter((t) => ids.has(t.id)), ctx.mesh);
|
|
6647
6648
|
const { staleTaskIds, staleReasons } = classifyStaleReplicas(finalTasks, TERMINAL);
|
|
6648
6649
|
const presentIds = new Set(finalTasks.map((t) => t.id));
|
|
6649
6650
|
for (const task of finalTasks) {
|
|
@@ -6851,11 +6852,11 @@ async function meshPruneStaleDirect(ctx, args = {}) {
|
|
|
6851
6852
|
const execute = args.execute === true && args.dry_run !== true;
|
|
6852
6853
|
const includeTerminal = args.include_terminal === true;
|
|
6853
6854
|
const liveNodes = await collectMeshViewQueueNodesWithLiveSessions(ctx);
|
|
6854
|
-
const ledgerEntries = (0,
|
|
6855
|
-
const directDispatches = (0,
|
|
6856
|
-
const result = (0,
|
|
6855
|
+
const ledgerEntries = (0, import_daemon_core5.readLedgerEntries)(ctx.mesh.id, { tail: 500 });
|
|
6856
|
+
const directDispatches = (0, import_daemon_core5.getActiveDirectDispatches)(ctx.mesh.id);
|
|
6857
|
+
const result = (0, import_daemon_core5.pruneStaleDirectDispatches)({
|
|
6857
6858
|
meshId: ctx.mesh.id,
|
|
6858
|
-
queue: (0,
|
|
6859
|
+
queue: (0, import_daemon_core5.getQueue)(ctx.mesh.id),
|
|
6859
6860
|
ledgerEntries,
|
|
6860
6861
|
directDispatches,
|
|
6861
6862
|
nodes: liveNodes,
|
|
@@ -6906,7 +6907,7 @@ async function meshSendTask(ctx, args) {
|
|
|
6906
6907
|
const requestedTaskMode = readString(args.task_mode) || readString(args.taskMode);
|
|
6907
6908
|
const readonly = args.readonly === true || args.read_only === true;
|
|
6908
6909
|
const missionId = readString(args.missionId) || readString(args.mission_id) || void 0;
|
|
6909
|
-
const modeValidation = (0,
|
|
6910
|
+
const modeValidation = (0, import_daemon_core5.validateMeshTaskModeRequest)(requestedTaskMode, message, readonly);
|
|
6910
6911
|
if (!modeValidation.valid) {
|
|
6911
6912
|
return JSON.stringify({
|
|
6912
6913
|
success: false,
|
|
@@ -7018,7 +7019,7 @@ async function meshSendTask(ctx, args) {
|
|
|
7018
7019
|
const dispatchedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
7019
7020
|
try {
|
|
7020
7021
|
const providerType = result2.providerType || cached?.providerType;
|
|
7021
|
-
(0,
|
|
7022
|
+
(0, import_daemon_core5.appendLedgerEntry)(ctx.mesh.id, {
|
|
7022
7023
|
kind: "task_dispatched",
|
|
7023
7024
|
nodeId: args.node_id,
|
|
7024
7025
|
sessionId: dispatchedSessionId,
|
|
@@ -7036,7 +7037,7 @@ async function meshSendTask(ctx, args) {
|
|
|
7036
7037
|
...coordinatorDaemonId ? { coordinatorDaemonId } : {}
|
|
7037
7038
|
})
|
|
7038
7039
|
});
|
|
7039
|
-
(0,
|
|
7040
|
+
(0, import_daemon_core5.insertDirectDispatch)(ctx.mesh.id, {
|
|
7040
7041
|
taskId,
|
|
7041
7042
|
nodeId: args.node_id,
|
|
7042
7043
|
sessionId: dispatchedSessionId,
|
|
@@ -7046,7 +7047,7 @@ async function meshSendTask(ctx, args) {
|
|
|
7046
7047
|
via: "p2p_direct",
|
|
7047
7048
|
dispatchedAt
|
|
7048
7049
|
});
|
|
7049
|
-
(0,
|
|
7050
|
+
(0, import_daemon_core5.recordDirectDispatchTask)(ctx.mesh.id, message, {
|
|
7050
7051
|
id: taskId,
|
|
7051
7052
|
...missionId ? { missionId } : {},
|
|
7052
7053
|
assignedNodeId: args.node_id,
|
|
@@ -7150,7 +7151,7 @@ async function meshSendTask(ctx, args) {
|
|
|
7150
7151
|
const { resolveDeliveryDecision } = await import("@adhdev/daemon-core");
|
|
7151
7152
|
const policyResult = resolveDeliveryDecision(sessionStatus, { kind: "task" });
|
|
7152
7153
|
if (policyResult.decision === "queued") {
|
|
7153
|
-
const queuedTask = (0,
|
|
7154
|
+
const queuedTask = (0, import_daemon_core5.enqueueTask)(ctx.mesh.id, message, {
|
|
7154
7155
|
targetNodeId: args.node_id,
|
|
7155
7156
|
targetSessionId: args.session_id,
|
|
7156
7157
|
taskMode,
|
|
@@ -7179,7 +7180,7 @@ async function meshSendTask(ctx, args) {
|
|
|
7179
7180
|
const dispatchedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
7180
7181
|
const coordinatorDaemonId = resolveCoordinatorDaemonId(ctx);
|
|
7181
7182
|
try {
|
|
7182
|
-
(0,
|
|
7183
|
+
(0, import_daemon_core5.appendLedgerEntry)(ctx.mesh.id, {
|
|
7183
7184
|
kind: "task_dispatched",
|
|
7184
7185
|
nodeId: args.node_id,
|
|
7185
7186
|
sessionId: args.session_id,
|
|
@@ -7200,7 +7201,7 @@ async function meshSendTask(ctx, args) {
|
|
|
7200
7201
|
});
|
|
7201
7202
|
} catch {
|
|
7202
7203
|
}
|
|
7203
|
-
(0,
|
|
7204
|
+
(0, import_daemon_core5.insertDirectDispatch)(ctx.mesh.id, {
|
|
7204
7205
|
taskId,
|
|
7205
7206
|
nodeId: args.node_id,
|
|
7206
7207
|
sessionId: args.session_id,
|
|
@@ -7213,7 +7214,7 @@ async function meshSendTask(ctx, args) {
|
|
|
7213
7214
|
});
|
|
7214
7215
|
let dispatchPreRecorded = false;
|
|
7215
7216
|
try {
|
|
7216
|
-
dispatchPreRecorded = (0,
|
|
7217
|
+
dispatchPreRecorded = (0, import_daemon_core5.getActiveDirectDispatches)(ctx.mesh.id).some((d) => d.taskId === taskId);
|
|
7217
7218
|
} catch {
|
|
7218
7219
|
}
|
|
7219
7220
|
const dispatchResult = await commandForNode(ctx, node, "agent_command", {
|
|
@@ -7235,7 +7236,7 @@ async function meshSendTask(ctx, args) {
|
|
|
7235
7236
|
const dispatchPayload = unwrapCommandPayload(dispatchResult);
|
|
7236
7237
|
if (dispatchPayload?.success === false || dispatchResult?.success === false) {
|
|
7237
7238
|
try {
|
|
7238
|
-
(0,
|
|
7239
|
+
(0, import_daemon_core5.deleteDirectDispatchesByTaskId)(ctx.mesh.id, [taskId]);
|
|
7239
7240
|
} catch {
|
|
7240
7241
|
}
|
|
7241
7242
|
dispatchPreRecorded = false;
|
|
@@ -7249,7 +7250,7 @@ async function meshSendTask(ctx, args) {
|
|
|
7249
7250
|
});
|
|
7250
7251
|
}
|
|
7251
7252
|
try {
|
|
7252
|
-
(0,
|
|
7253
|
+
(0, import_daemon_core5.recordDirectDispatchTask)(ctx.mesh.id, message, {
|
|
7253
7254
|
id: taskId,
|
|
7254
7255
|
...missionId ? { missionId } : {},
|
|
7255
7256
|
assignedNodeId: args.node_id,
|
|
@@ -7294,7 +7295,7 @@ async function meshSendTask(ctx, args) {
|
|
|
7294
7295
|
...buildMissionInactiveWarning(ctx, missionId) ?? {}
|
|
7295
7296
|
});
|
|
7296
7297
|
}
|
|
7297
|
-
const task = (0,
|
|
7298
|
+
const task = (0, import_daemon_core5.enqueueTask)(ctx.mesh.id, message, {
|
|
7298
7299
|
targetNodeId: args.node_id,
|
|
7299
7300
|
targetSessionId: args.session_id,
|
|
7300
7301
|
taskMode,
|
|
@@ -7303,7 +7304,7 @@ async function meshSendTask(ctx, args) {
|
|
|
7303
7304
|
...ctx.coordinatorSessionId ? { sourceCoordinatorSessionId: ctx.coordinatorSessionId } : {}
|
|
7304
7305
|
});
|
|
7305
7306
|
const queueTrigger = await triggerMeshQueueAndReport(ctx);
|
|
7306
|
-
const pendingEvents = (0,
|
|
7307
|
+
const pendingEvents = (0, import_daemon_core5.drainPendingMeshCoordinatorEvents)(ctx.mesh.id, ctx.localDaemonId);
|
|
7307
7308
|
const result = {
|
|
7308
7309
|
success: true,
|
|
7309
7310
|
source: "queue",
|
|
@@ -7349,7 +7350,7 @@ async function meshReadChat(ctx, args) {
|
|
|
7349
7350
|
tailLimit: args.tail ?? 10
|
|
7350
7351
|
});
|
|
7351
7352
|
} catch (e) {
|
|
7352
|
-
if (isLocalNode || !(0,
|
|
7353
|
+
if (isLocalNode || !(0, import_daemon_core5.isP2pRelayTransportFailure)(e)) throw e;
|
|
7353
7354
|
return buildMeshReadChatCacheFallback(ctx, args, node, e);
|
|
7354
7355
|
}
|
|
7355
7356
|
const payload = annotateRapidReadChatAdvisory(unwrapCommandPayload(result), {
|
|
@@ -7438,7 +7439,7 @@ async function meshSendKeys(ctx, args) {
|
|
|
7438
7439
|
const auditKeys = requestedKeys.slice(0, 64);
|
|
7439
7440
|
const recordAudit = (result2, extra = {}) => {
|
|
7440
7441
|
try {
|
|
7441
|
-
(0,
|
|
7442
|
+
(0, import_daemon_core5.appendLedgerEntry)(ctx.mesh.id, {
|
|
7442
7443
|
kind: "key_injection",
|
|
7443
7444
|
nodeId: args.node_id,
|
|
7444
7445
|
sessionId: args.session_id,
|
|
@@ -7455,7 +7456,7 @@ async function meshSendKeys(ctx, args) {
|
|
|
7455
7456
|
}
|
|
7456
7457
|
};
|
|
7457
7458
|
if (hasDestructive) {
|
|
7458
|
-
const policyAllows = (0,
|
|
7459
|
+
const policyAllows = (0, import_daemon_core5.resolveAllowSendKeysDestructive)(ctx.mesh.policy, node.policy);
|
|
7459
7460
|
if (args.confirm_destructive !== true || !policyAllows) {
|
|
7460
7461
|
recordAudit("refused", { refused: "destructive_gate", policyAllows });
|
|
7461
7462
|
return JSON.stringify({
|
|
@@ -7537,14 +7538,14 @@ async function meshLaunchSession(ctx, args) {
|
|
|
7537
7538
|
const coordinatorNode = resolveCoordinatorNode(ctx);
|
|
7538
7539
|
const coordinatorDaemonId = resolveCoordinatorDaemonId(ctx);
|
|
7539
7540
|
const spawnedSessionVisibility = readSpawnedSessionVisibility(ctx.mesh.policy);
|
|
7540
|
-
const delegatedWorkerAutoApprove = (0,
|
|
7541
|
+
const delegatedWorkerAutoApprove = (0, import_daemon_core5.resolveDelegatedWorkerAutoApprove)(ctx.mesh.policy, node.policy);
|
|
7541
7542
|
let requestedAutoApproveMode;
|
|
7542
|
-
const delegatedWorkerDangerousModeAllow = (0,
|
|
7543
|
+
const delegatedWorkerDangerousModeAllow = (0, import_daemon_core5.resolveDelegatedWorkerDangerousModeAllow)(ctx.mesh.policy, node.policy);
|
|
7543
7544
|
if (delegatedWorkerAutoApprove !== false) {
|
|
7544
7545
|
try {
|
|
7545
7546
|
const ws = typeof node.workspace === "string" && node.workspace.trim() ? node.workspace.trim() : "";
|
|
7546
7547
|
if (ws) {
|
|
7547
|
-
const repo = (0,
|
|
7548
|
+
const repo = (0, import_daemon_core5.loadRepoMeshJsonConfig)(ws);
|
|
7548
7549
|
const repoMode = repo.sourceType === "repo_file" ? repo.config?.providerDefaults?.autoApproveModes?.[resolvedProviderType] : void 0;
|
|
7549
7550
|
if (typeof repoMode === "string" && repoMode.trim()) requestedAutoApproveMode = repoMode.trim();
|
|
7550
7551
|
}
|
|
@@ -7641,7 +7642,7 @@ async function meshLaunchSession(ctx, args) {
|
|
|
7641
7642
|
});
|
|
7642
7643
|
}
|
|
7643
7644
|
try {
|
|
7644
|
-
(0,
|
|
7645
|
+
(0, import_daemon_core5.appendLedgerEntry)(ctx.mesh.id, {
|
|
7645
7646
|
kind: "session_launched",
|
|
7646
7647
|
nodeId: args.node_id,
|
|
7647
7648
|
sessionId: runtimeSessionId || void 0,
|
|
@@ -7694,26 +7695,26 @@ async function meshAnswerQuestion(ctx, args) {
|
|
|
7694
7695
|
return JSON.stringify(result, null, 2);
|
|
7695
7696
|
}
|
|
7696
7697
|
async function meshListPendingApprovals(ctx, _args = {}) {
|
|
7697
|
-
(0,
|
|
7698
|
+
(0, import_daemon_core5.recordMeshToolCall)({ meshId: ctx.mesh.id, tool: "mesh_list_pending_approvals" });
|
|
7698
7699
|
await refreshMeshFromDaemon(ctx);
|
|
7699
7700
|
const liveNodes = await collectMeshViewQueueNodesWithLiveSessions(ctx);
|
|
7700
|
-
let ledgerEntries = (0,
|
|
7701
|
-
let directDispatches = (0,
|
|
7701
|
+
let ledgerEntries = (0, import_daemon_core5.readLedgerEntries)(ctx.mesh.id, { tail: 200 });
|
|
7702
|
+
let directDispatches = (0, import_daemon_core5.getActiveDirectDispatches)(ctx.mesh.id);
|
|
7702
7703
|
const directReconciliation = await reconcileDirectDispatchesFromTranscriptEvidence(ctx, liveNodes, directDispatches, ledgerEntries);
|
|
7703
7704
|
if (directReconciliation.reconciled > 0) {
|
|
7704
|
-
ledgerEntries = (0,
|
|
7705
|
-
directDispatches = (0,
|
|
7705
|
+
ledgerEntries = (0, import_daemon_core5.readLedgerEntries)(ctx.mesh.id, { tail: 200 });
|
|
7706
|
+
directDispatches = (0, import_daemon_core5.getActiveDirectDispatches)(ctx.mesh.id);
|
|
7706
7707
|
}
|
|
7707
|
-
(0,
|
|
7708
|
-
directDispatches = (0,
|
|
7709
|
-
const activeWorkEvidence = (0,
|
|
7708
|
+
(0, import_daemon_core5.markStaleDirectDispatches)(ctx.mesh.id);
|
|
7709
|
+
directDispatches = (0, import_daemon_core5.getActiveDirectDispatches)(ctx.mesh.id);
|
|
7710
|
+
const activeWorkEvidence = (0, import_daemon_core5.buildMeshActiveWork)({
|
|
7710
7711
|
meshId: ctx.mesh.id,
|
|
7711
|
-
queue: (0,
|
|
7712
|
+
queue: (0, import_daemon_core5.getQueue)(ctx.mesh.id),
|
|
7712
7713
|
ledgerEntries,
|
|
7713
7714
|
directDispatches,
|
|
7714
7715
|
nodes: liveNodes
|
|
7715
7716
|
});
|
|
7716
|
-
const approvals = (0,
|
|
7717
|
+
const approvals = (0, import_daemon_core5.collectPendingApprovals)(activeWorkEvidence.activeWork);
|
|
7717
7718
|
return JSON.stringify({
|
|
7718
7719
|
count: approvals.length,
|
|
7719
7720
|
approvals,
|
|
@@ -7875,7 +7876,7 @@ async function meshCheckpoint(ctx, args) {
|
|
|
7875
7876
|
includeUntracked: true
|
|
7876
7877
|
});
|
|
7877
7878
|
try {
|
|
7878
|
-
(0,
|
|
7879
|
+
(0, import_daemon_core5.appendLedgerEntry)(ctx.mesh.id, {
|
|
7879
7880
|
kind: "checkpoint_created",
|
|
7880
7881
|
nodeId: args.node_id,
|
|
7881
7882
|
payload: {
|