@adhdev/daemon-core 0.9.82-rc.272 → 0.9.82-rc.274
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/boot/daemon-lifecycle.d.ts +3 -0
- package/dist/index.js +199 -128
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +199 -128
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/mesh-events-coordinator.d.ts +1 -21
- package/dist/mesh/mesh-events-pending.d.ts +0 -7
- package/dist/mesh/mesh-events.d.ts +2 -1
- package/dist/mesh/mesh-missions.d.ts +10 -0
- package/dist/mesh/mesh-reconcile-loop.d.ts +7 -0
- package/dist/repo-mesh-types.d.ts +8 -0
- package/package.json +2 -2
- package/src/boot/daemon-lifecycle.ts +16 -2
- package/src/commands/router.ts +14 -21
- package/src/mesh/mesh-events-coordinator.ts +31 -107
- package/src/mesh/mesh-events-pending.ts +14 -56
- package/src/mesh/mesh-events.ts +5 -1
- package/src/mesh/mesh-missions.ts +21 -0
- package/src/mesh/mesh-reconcile-loop.ts +256 -0
- package/src/providers/cli-provider-instance.ts +23 -0
- package/src/repo-mesh-types.ts +8 -0
|
@@ -82,6 +82,9 @@ export interface DaemonComponents {
|
|
|
82
82
|
refreshProviderAvailability: (providerType?: string) => Promise<void>;
|
|
83
83
|
dispatchMeshCommand?: (daemonId: string, command: string, args: Record<string, unknown>) => Promise<any>;
|
|
84
84
|
onMeshCoordinatorEventForwarded?: (payload: Record<string, unknown>) => void;
|
|
85
|
+
meshReconcileLoop?: {
|
|
86
|
+
stop(): void;
|
|
87
|
+
};
|
|
85
88
|
}
|
|
86
89
|
export interface DaemonDevSupportOptions {
|
|
87
90
|
components: DaemonComponents;
|
package/dist/index.js
CHANGED
|
@@ -275,10 +275,10 @@ function readInjected(value) {
|
|
|
275
275
|
}
|
|
276
276
|
function getDaemonBuildInfo() {
|
|
277
277
|
if (cached) return cached;
|
|
278
|
-
const commit = readInjected(true ? "
|
|
279
|
-
const commitShort = readInjected(true ? "
|
|
280
|
-
const version = readInjected(true ? "0.9.82-rc.
|
|
281
|
-
const builtAt = readInjected(true ? "2026-06-
|
|
278
|
+
const commit = readInjected(true ? "89d1ac61612c1dfe7fac53be61ec5dbfa67d00b2" : void 0) ?? "unknown";
|
|
279
|
+
const commitShort = readInjected(true ? "89d1ac61" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
280
|
+
const version = readInjected(true ? "0.9.82-rc.274" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
281
|
+
const builtAt = readInjected(true ? "2026-06-15T07:04:52.710Z" : void 0);
|
|
282
282
|
cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
|
|
283
283
|
return cached;
|
|
284
284
|
}
|
|
@@ -4384,6 +4384,7 @@ __export(mesh_missions_exports, {
|
|
|
4384
4384
|
getActiveMeshMissionSummaries: () => getActiveMeshMissionSummaries,
|
|
4385
4385
|
getMeshMission: () => getMeshMission,
|
|
4386
4386
|
getMeshMissions: () => getMeshMissions,
|
|
4387
|
+
getMeshStatusMissionSummaries: () => getMeshStatusMissionSummaries,
|
|
4387
4388
|
summarizeMeshMission: () => summarizeMeshMission,
|
|
4388
4389
|
summarizeMissionTasks: () => summarizeMissionTasks,
|
|
4389
4390
|
upsertMeshMission: () => upsertMeshMission
|
|
@@ -4449,6 +4450,13 @@ function summarizeMeshMission(meshId, mission) {
|
|
|
4449
4450
|
function getActiveMeshMissionSummaries(meshId) {
|
|
4450
4451
|
return getMeshMissions(meshId, ["active"]).map((mission) => summarizeMeshMission(meshId, mission));
|
|
4451
4452
|
}
|
|
4453
|
+
function getMeshStatusMissionSummaries(meshId, options) {
|
|
4454
|
+
const historyLimit = Math.max(0, options?.historyLimit ?? 10);
|
|
4455
|
+
const all = getMeshMissions(meshId);
|
|
4456
|
+
const live = all.filter((m) => m.status === "active" || m.status === "paused");
|
|
4457
|
+
const history = all.filter((m) => m.status === "completed" || m.status === "abandoned").sort((a, b) => (b.updatedAt || "").localeCompare(a.updatedAt || "")).slice(0, historyLimit);
|
|
4458
|
+
return [...live, ...history].map((mission) => summarizeMeshMission(meshId, mission));
|
|
4459
|
+
}
|
|
4452
4460
|
function buildMissionPromptSection(meshId) {
|
|
4453
4461
|
const summaries = getActiveMeshMissionSummaries(meshId);
|
|
4454
4462
|
if (summaries.length === 0) return "";
|
|
@@ -6160,16 +6168,6 @@ function readNonEmptyString2(value) {
|
|
|
6160
6168
|
function readRecord3(value) {
|
|
6161
6169
|
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
6162
6170
|
}
|
|
6163
|
-
function canonicalDaemonId(value) {
|
|
6164
|
-
const id = readNonEmptyString2(value);
|
|
6165
|
-
if (!id) return "";
|
|
6166
|
-
return id.replace(/^(?:daemon|standalone)_/, "");
|
|
6167
|
-
}
|
|
6168
|
-
function sameDaemonId(a, b) {
|
|
6169
|
-
const ca = canonicalDaemonId(a);
|
|
6170
|
-
const cb = canonicalDaemonId(b);
|
|
6171
|
-
return ca !== "" && ca === cb;
|
|
6172
|
-
}
|
|
6173
6171
|
function buildMeshWorkerRelayStamp(currentSettings, meshContext) {
|
|
6174
6172
|
if (!meshContext) return void 0;
|
|
6175
6173
|
const settings = currentSettings && typeof currentSettings === "object" ? currentSettings : {};
|
|
@@ -6370,29 +6368,6 @@ function buildPendingEventFingerprint(event) {
|
|
|
6370
6368
|
timestamp || ""
|
|
6371
6369
|
].join("::");
|
|
6372
6370
|
}
|
|
6373
|
-
function markMeshCoordinatorEventDirectDelivered(coordinatorDaemonId, event) {
|
|
6374
|
-
const canonical = canonicalDaemonId(coordinatorDaemonId);
|
|
6375
|
-
if (!canonical) return;
|
|
6376
|
-
const fingerprint = buildPendingEventFingerprint(event);
|
|
6377
|
-
if (!fingerprint.trim()) return;
|
|
6378
|
-
try {
|
|
6379
|
-
const store = MeshRuntimeStore.getInstance();
|
|
6380
|
-
store.recordDirectDelivered(canonical, fingerprint, DIRECT_DELIVERED_TTL_MS);
|
|
6381
|
-
store.sweepExpiredDirectDelivered();
|
|
6382
|
-
} catch {
|
|
6383
|
-
}
|
|
6384
|
-
}
|
|
6385
|
-
function wasDirectDeliveredToCoordinator(coordinatorDaemonId, event) {
|
|
6386
|
-
const canonical = canonicalDaemonId(coordinatorDaemonId);
|
|
6387
|
-
if (!canonical) return false;
|
|
6388
|
-
const fingerprint = buildPendingEventFingerprint(event);
|
|
6389
|
-
if (!fingerprint.trim()) return false;
|
|
6390
|
-
try {
|
|
6391
|
-
return MeshRuntimeStore.getInstance().wasDirectDelivered(canonical, fingerprint);
|
|
6392
|
-
} catch {
|
|
6393
|
-
return false;
|
|
6394
|
-
}
|
|
6395
|
-
}
|
|
6396
6371
|
function hasPendingCoordinatorEventDuplicate(event) {
|
|
6397
6372
|
const fingerprint = buildPendingEventFingerprint(event);
|
|
6398
6373
|
if (!fingerprint.trim()) return false;
|
|
@@ -6591,9 +6566,7 @@ function drainPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
|
|
|
6591
6566
|
for (const event of filtered) pushUnique(event);
|
|
6592
6567
|
}
|
|
6593
6568
|
if (merged.length === 0) return [];
|
|
6594
|
-
|
|
6595
|
-
if (deliverable.length === 0) return [];
|
|
6596
|
-
return reconcilePendingMeshCoordinatorEvents(meshId, deliverable);
|
|
6569
|
+
return reconcilePendingMeshCoordinatorEvents(meshId, merged);
|
|
6597
6570
|
}
|
|
6598
6571
|
function getPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
|
|
6599
6572
|
if (!meshId) return [];
|
|
@@ -6620,8 +6593,7 @@ function getPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
|
|
|
6620
6593
|
for (const event of readPendingMeshCoordinatorEventsFromDisk(meshId, coordinatorDaemonId)) {
|
|
6621
6594
|
pushUnique(event);
|
|
6622
6595
|
}
|
|
6623
|
-
|
|
6624
|
-
return reconcilePendingMeshCoordinatorEvents(meshId, deliverable);
|
|
6596
|
+
return reconcilePendingMeshCoordinatorEvents(meshId, merged);
|
|
6625
6597
|
}
|
|
6626
6598
|
function clearPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
|
|
6627
6599
|
if (!meshId) return;
|
|
@@ -6637,7 +6609,7 @@ function clearPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
|
|
|
6637
6609
|
}
|
|
6638
6610
|
}
|
|
6639
6611
|
}
|
|
6640
|
-
var import_fs8, import_path8, import_crypto7, REFINE_TERMINAL_EVENTS,
|
|
6612
|
+
var import_fs8, import_path8, import_crypto7, REFINE_TERMINAL_EVENTS, MAX_PENDING_EVENTS_BYTES, MAX_PENDING_EVENTS_KEEP;
|
|
6641
6613
|
var init_mesh_events_pending = __esm({
|
|
6642
6614
|
"src/mesh/mesh-events-pending.ts"() {
|
|
6643
6615
|
"use strict";
|
|
@@ -6649,7 +6621,6 @@ var init_mesh_events_pending = __esm({
|
|
|
6649
6621
|
init_mesh_runtime_store();
|
|
6650
6622
|
init_mesh_events_utils();
|
|
6651
6623
|
REFINE_TERMINAL_EVENTS = /* @__PURE__ */ new Set(["refine:completed", "refine:failed"]);
|
|
6652
|
-
DIRECT_DELIVERED_TTL_MS = 10 * 60 * 1e3;
|
|
6653
6624
|
MAX_PENDING_EVENTS_BYTES = 100 * 1024;
|
|
6654
6625
|
MAX_PENDING_EVENTS_KEEP = 50;
|
|
6655
6626
|
}
|
|
@@ -8011,7 +7982,6 @@ function injectMeshSystemMessage(components, args) {
|
|
|
8011
7982
|
const workerCoordinatorDaemonId = readNonEmptyString2(
|
|
8012
7983
|
sourceSession?.getState()?.settings?.meshCoordinatorDaemonId
|
|
8013
7984
|
);
|
|
8014
|
-
const localDaemonId = readNonEmptyString2(loadConfig().machineId);
|
|
8015
7985
|
if (components.onMeshCoordinatorEventForwarded) {
|
|
8016
7986
|
try {
|
|
8017
7987
|
components.onMeshCoordinatorEventForwarded({
|
|
@@ -8366,60 +8336,6 @@ function injectMeshSystemMessage(components, args) {
|
|
|
8366
8336
|
recoveryContext
|
|
8367
8337
|
});
|
|
8368
8338
|
if (!messageText) return { success: false, error: "unsupported mesh event" };
|
|
8369
|
-
const coordinatorInstances = components.instanceManager.getByCategory("cli").filter((inst) => {
|
|
8370
|
-
const instState = inst.getState();
|
|
8371
|
-
if (instState.settings?.meshCoordinatorFor !== args.meshId) return false;
|
|
8372
|
-
if (args.sourceInstanceId && instState.instanceId === args.sourceInstanceId) return false;
|
|
8373
|
-
if (workerCoordinatorDaemonId && localDaemonId && !sameDaemonId(workerCoordinatorDaemonId, localDaemonId)) return false;
|
|
8374
|
-
return true;
|
|
8375
|
-
});
|
|
8376
|
-
if (coordinatorInstances.length === 0) {
|
|
8377
|
-
const remoteCoordinatorDaemonId = workerCoordinatorDaemonId && localDaemonId && !sameDaemonId(workerCoordinatorDaemonId, localDaemonId) ? workerCoordinatorDaemonId : "";
|
|
8378
|
-
if (remoteCoordinatorDaemonId && components.dispatchMeshCommand) {
|
|
8379
|
-
const forwardPayload = {
|
|
8380
|
-
event: args.event,
|
|
8381
|
-
meshId: args.meshId,
|
|
8382
|
-
nodeId: args.nodeId || void 0,
|
|
8383
|
-
workspace: readNonEmptyString2(args.metadataEvent.workspace),
|
|
8384
|
-
...args.metadataEvent,
|
|
8385
|
-
...recoveryContext ? { recoveryContext } : {}
|
|
8386
|
-
};
|
|
8387
|
-
components.dispatchMeshCommand(remoteCoordinatorDaemonId, "mesh_forward_event", forwardPayload).then(() => {
|
|
8388
|
-
LOG.info("MeshEvents", `Forwarded ${args.event} for mesh ${args.meshId} to remote coordinator daemon ${remoteCoordinatorDaemonId.slice(0, 12)}\u2026`);
|
|
8389
|
-
}).catch((error) => {
|
|
8390
|
-
LOG.warn("MeshEvents", `Remote forward of ${args.event} failed (${error?.message || error}); queuing for backfill`);
|
|
8391
|
-
queuePendingMeshCoordinatorEvent({
|
|
8392
|
-
event: args.event,
|
|
8393
|
-
meshId: args.meshId,
|
|
8394
|
-
nodeLabel: args.nodeLabel,
|
|
8395
|
-
nodeId: args.nodeId || void 0,
|
|
8396
|
-
workspace: readNonEmptyString2(args.metadataEvent.workspace),
|
|
8397
|
-
metadataEvent: { ...args.metadataEvent, ...recoveryContext ? { recoveryContext } : {} },
|
|
8398
|
-
coordinatorMessage: messageText,
|
|
8399
|
-
queuedAt: Date.now(),
|
|
8400
|
-
targetCoordinatorDaemonId: remoteCoordinatorDaemonId
|
|
8401
|
-
});
|
|
8402
|
-
});
|
|
8403
|
-
return { success: true, forwarded: 0, remoteForwarded: true };
|
|
8404
|
-
}
|
|
8405
|
-
if (queuePendingMeshCoordinatorEvent({
|
|
8406
|
-
event: args.event,
|
|
8407
|
-
meshId: args.meshId,
|
|
8408
|
-
nodeLabel: args.nodeLabel,
|
|
8409
|
-
nodeId: args.nodeId || void 0,
|
|
8410
|
-
workspace: readNonEmptyString2(args.metadataEvent.workspace),
|
|
8411
|
-
metadataEvent: {
|
|
8412
|
-
...args.metadataEvent,
|
|
8413
|
-
...recoveryContext ? { recoveryContext } : {}
|
|
8414
|
-
},
|
|
8415
|
-
coordinatorMessage: messageText,
|
|
8416
|
-
queuedAt: Date.now(),
|
|
8417
|
-
...workerCoordinatorDaemonId ? { targetCoordinatorDaemonId: workerCoordinatorDaemonId } : {}
|
|
8418
|
-
})) {
|
|
8419
|
-
LOG.info("MeshEvents", `Queued ${args.event} for MCP coordinator (mesh ${args.meshId}${workerCoordinatorDaemonId ? `, coordinator daemon ${workerCoordinatorDaemonId}` : ""})`);
|
|
8420
|
-
}
|
|
8421
|
-
return { success: true, forwarded: 0 };
|
|
8422
|
-
}
|
|
8423
8339
|
const pendingEvent = {
|
|
8424
8340
|
event: args.event,
|
|
8425
8341
|
meshId: args.meshId,
|
|
@@ -8435,21 +8351,9 @@ function injectMeshSystemMessage(components, args) {
|
|
|
8435
8351
|
...workerCoordinatorDaemonId ? { targetCoordinatorDaemonId: workerCoordinatorDaemonId } : {}
|
|
8436
8352
|
};
|
|
8437
8353
|
if (queuePendingMeshCoordinatorEvent(pendingEvent)) {
|
|
8438
|
-
LOG.info("MeshEvents", `Queued ${args.event} for
|
|
8439
|
-
}
|
|
8440
|
-
if (localDaemonId) {
|
|
8441
|
-
markMeshCoordinatorEventDirectDelivered(localDaemonId, pendingEvent);
|
|
8442
|
-
}
|
|
8443
|
-
const forceInject = shouldForceInjectMeshEvent(args.event);
|
|
8444
|
-
for (const coord of coordinatorInstances) {
|
|
8445
|
-
const coordState = coord.getState();
|
|
8446
|
-
LOG.info("MeshEvents", `Forwarding mesh event to coordinator ${coordState.instanceId}${forceInject ? " (force)" : ""}`);
|
|
8447
|
-
coord.onEvent("send_message", {
|
|
8448
|
-
input: { text: messageText, textFallback: messageText },
|
|
8449
|
-
...forceInject ? { force: true } : {}
|
|
8450
|
-
});
|
|
8354
|
+
LOG.info("MeshEvents", `Queued ${args.event} for coordinator (mesh ${args.meshId}${workerCoordinatorDaemonId ? `, coordinator daemon ${workerCoordinatorDaemonId}` : ""})`);
|
|
8451
8355
|
}
|
|
8452
|
-
return { success: true, forwarded:
|
|
8356
|
+
return { success: true, forwarded: 0 };
|
|
8453
8357
|
}
|
|
8454
8358
|
function handleMeshForwardEvent(components, payload) {
|
|
8455
8359
|
const eventName = readNonEmptyString2(payload.event);
|
|
@@ -8620,6 +8524,169 @@ var init_mesh_events_coordinator = __esm({
|
|
|
8620
8524
|
}
|
|
8621
8525
|
});
|
|
8622
8526
|
|
|
8527
|
+
// src/mesh/mesh-reconcile-loop.ts
|
|
8528
|
+
function resolveReconcileIntervalMs() {
|
|
8529
|
+
const raw = readNonEmptyString2(process.env.MESH_RECONCILE_INTERVAL_MS);
|
|
8530
|
+
if (raw) {
|
|
8531
|
+
const parsed = Number.parseInt(raw, 10);
|
|
8532
|
+
if (Number.isFinite(parsed) && parsed >= 1e3 && parsed <= 6e4) return parsed;
|
|
8533
|
+
}
|
|
8534
|
+
return DEFAULT_RECONCILE_INTERVAL_MS;
|
|
8535
|
+
}
|
|
8536
|
+
function findLiveCoordinators(components) {
|
|
8537
|
+
const out = [];
|
|
8538
|
+
for (const inst of components.instanceManager.getByCategory("cli")) {
|
|
8539
|
+
const state = inst.getState();
|
|
8540
|
+
const settings = state.settings && typeof state.settings === "object" ? state.settings : {};
|
|
8541
|
+
const meshId = readNonEmptyString2(settings.meshCoordinatorFor);
|
|
8542
|
+
if (!meshId) continue;
|
|
8543
|
+
const status = readNonEmptyString2(state.status).toLowerCase();
|
|
8544
|
+
out.push({ meshId, instance: inst, idle: status === "idle" });
|
|
8545
|
+
}
|
|
8546
|
+
return out;
|
|
8547
|
+
}
|
|
8548
|
+
function injectPendingIntoCoordinator(coordinator, pending) {
|
|
8549
|
+
if (!coordinator || !pending.coordinatorMessage) return;
|
|
8550
|
+
const force = shouldForceInjectMeshEvent(pending.event);
|
|
8551
|
+
coordinator.onEvent("send_message", {
|
|
8552
|
+
input: { text: pending.coordinatorMessage, textFallback: pending.coordinatorMessage },
|
|
8553
|
+
...force ? { force: true } : {}
|
|
8554
|
+
});
|
|
8555
|
+
}
|
|
8556
|
+
async function runMeshReconcileTick(components) {
|
|
8557
|
+
const coordinators = findLiveCoordinators(components);
|
|
8558
|
+
if (coordinators.length === 0) {
|
|
8559
|
+
return;
|
|
8560
|
+
}
|
|
8561
|
+
const byMesh = /* @__PURE__ */ new Map();
|
|
8562
|
+
for (const c of coordinators) {
|
|
8563
|
+
const list = byMesh.get(c.meshId);
|
|
8564
|
+
if (list) list.push(c);
|
|
8565
|
+
else byMesh.set(c.meshId, [c]);
|
|
8566
|
+
}
|
|
8567
|
+
const localDaemonId = readNonEmptyString2(loadConfig().machineId) || void 0;
|
|
8568
|
+
const dispatchMeshCommand = components.dispatchMeshCommand;
|
|
8569
|
+
const store = (() => {
|
|
8570
|
+
try {
|
|
8571
|
+
return MeshRuntimeStore.getInstance();
|
|
8572
|
+
} catch {
|
|
8573
|
+
return void 0;
|
|
8574
|
+
}
|
|
8575
|
+
})();
|
|
8576
|
+
for (const [meshId, meshCoordinators] of byMesh) {
|
|
8577
|
+
if (dispatchMeshCommand) {
|
|
8578
|
+
try {
|
|
8579
|
+
await pullRemoteNodeQueues(components, meshId, localDaemonId);
|
|
8580
|
+
} catch (e) {
|
|
8581
|
+
LOG.warn("MeshReconcile", `Remote node pull failed for mesh ${meshId}: ${e?.message || e}`);
|
|
8582
|
+
}
|
|
8583
|
+
}
|
|
8584
|
+
const idleCoordinators = meshCoordinators.filter((c) => c.idle);
|
|
8585
|
+
if (idleCoordinators.length === 0) continue;
|
|
8586
|
+
if (store) {
|
|
8587
|
+
try {
|
|
8588
|
+
if (store.pendingEventCount(meshId) === 0) continue;
|
|
8589
|
+
} catch {
|
|
8590
|
+
}
|
|
8591
|
+
}
|
|
8592
|
+
let pendingEvents = [];
|
|
8593
|
+
try {
|
|
8594
|
+
pendingEvents = drainPendingMeshCoordinatorEvents(meshId, localDaemonId);
|
|
8595
|
+
} catch (e) {
|
|
8596
|
+
LOG.warn("MeshReconcile", `Drain failed for mesh ${meshId}: ${e?.message || e}`);
|
|
8597
|
+
continue;
|
|
8598
|
+
}
|
|
8599
|
+
if (pendingEvents.length === 0) continue;
|
|
8600
|
+
LOG.info("MeshReconcile", `Reconcile inject: ${pendingEvents.length} pending event(s) \u2192 ${idleCoordinators.length} idle coordinator(s) for mesh ${meshId}`);
|
|
8601
|
+
for (const pending of pendingEvents) {
|
|
8602
|
+
for (const c of idleCoordinators) {
|
|
8603
|
+
injectPendingIntoCoordinator(c.instance, pending);
|
|
8604
|
+
}
|
|
8605
|
+
}
|
|
8606
|
+
}
|
|
8607
|
+
}
|
|
8608
|
+
async function pullRemoteNodeQueues(components, meshId, localDaemonId) {
|
|
8609
|
+
const dispatchMeshCommand = components.dispatchMeshCommand;
|
|
8610
|
+
if (!dispatchMeshCommand) return;
|
|
8611
|
+
const mesh = listMeshes().find((m) => m.id === meshId);
|
|
8612
|
+
if (!mesh) return;
|
|
8613
|
+
const pendingEventArgs = {
|
|
8614
|
+
meshId,
|
|
8615
|
+
...localDaemonId ? { coordinatorDaemonId: localDaemonId } : {}
|
|
8616
|
+
};
|
|
8617
|
+
for (const node of mesh.nodes) {
|
|
8618
|
+
const nodeDaemonId = readNonEmptyString2(node.daemonId);
|
|
8619
|
+
if (!nodeDaemonId) continue;
|
|
8620
|
+
if (localDaemonId && nodeDaemonId === localDaemonId) continue;
|
|
8621
|
+
let events;
|
|
8622
|
+
try {
|
|
8623
|
+
events = await dispatchMeshCommand(nodeDaemonId, "get_pending_mesh_events", pendingEventArgs);
|
|
8624
|
+
} catch {
|
|
8625
|
+
continue;
|
|
8626
|
+
}
|
|
8627
|
+
const list = extractPendingEvents(events).filter((e) => readNonEmptyString2(e?.meshId) === meshId);
|
|
8628
|
+
for (const event of list) {
|
|
8629
|
+
const payload = buildForwardPayloadFromPending(event);
|
|
8630
|
+
if (!payload.event || !payload.meshId) continue;
|
|
8631
|
+
try {
|
|
8632
|
+
handleMeshForwardEvent(components, payload);
|
|
8633
|
+
} catch {
|
|
8634
|
+
}
|
|
8635
|
+
}
|
|
8636
|
+
}
|
|
8637
|
+
}
|
|
8638
|
+
function extractPendingEvents(raw) {
|
|
8639
|
+
if (Array.isArray(raw)) return raw;
|
|
8640
|
+
if (raw && typeof raw === "object") {
|
|
8641
|
+
const events = raw.events;
|
|
8642
|
+
if (Array.isArray(events)) return events;
|
|
8643
|
+
}
|
|
8644
|
+
return [];
|
|
8645
|
+
}
|
|
8646
|
+
function buildForwardPayloadFromPending(event) {
|
|
8647
|
+
const metadata = event?.metadataEvent && typeof event.metadataEvent === "object" ? event.metadataEvent : {};
|
|
8648
|
+
return {
|
|
8649
|
+
event: readNonEmptyString2(event?.event),
|
|
8650
|
+
meshId: readNonEmptyString2(event?.meshId),
|
|
8651
|
+
nodeId: readNonEmptyString2(event?.nodeId) || readNonEmptyString2(metadata.meshNodeId),
|
|
8652
|
+
workspace: readNonEmptyString2(event?.workspace) || readNonEmptyString2(metadata.workspace),
|
|
8653
|
+
...metadata
|
|
8654
|
+
};
|
|
8655
|
+
}
|
|
8656
|
+
function setupMeshReconcileLoop(components) {
|
|
8657
|
+
const intervalMs = resolveReconcileIntervalMs();
|
|
8658
|
+
let running = false;
|
|
8659
|
+
const timer = setInterval(() => {
|
|
8660
|
+
if (running) return;
|
|
8661
|
+
running = true;
|
|
8662
|
+
void runMeshReconcileTick(components).catch((e) => LOG.warn("MeshReconcile", `Reconcile tick error: ${e?.message || e}`)).finally(() => {
|
|
8663
|
+
running = false;
|
|
8664
|
+
});
|
|
8665
|
+
}, intervalMs);
|
|
8666
|
+
if (typeof timer.unref === "function") timer.unref();
|
|
8667
|
+
LOG.info("MeshReconcile", `Mesh reconcile loop started (interval ${intervalMs}ms)`);
|
|
8668
|
+
return {
|
|
8669
|
+
stop() {
|
|
8670
|
+
clearInterval(timer);
|
|
8671
|
+
LOG.info("MeshReconcile", "Mesh reconcile loop stopped");
|
|
8672
|
+
}
|
|
8673
|
+
};
|
|
8674
|
+
}
|
|
8675
|
+
var DEFAULT_RECONCILE_INTERVAL_MS;
|
|
8676
|
+
var init_mesh_reconcile_loop = __esm({
|
|
8677
|
+
"src/mesh/mesh-reconcile-loop.ts"() {
|
|
8678
|
+
"use strict";
|
|
8679
|
+
init_config();
|
|
8680
|
+
init_mesh_config();
|
|
8681
|
+
init_logger();
|
|
8682
|
+
init_mesh_events_pending();
|
|
8683
|
+
init_mesh_runtime_store();
|
|
8684
|
+
init_mesh_events_coordinator();
|
|
8685
|
+
init_mesh_events_utils();
|
|
8686
|
+
DEFAULT_RECONCILE_INTERVAL_MS = 4e3;
|
|
8687
|
+
}
|
|
8688
|
+
});
|
|
8689
|
+
|
|
8623
8690
|
// src/mesh/mesh-events.ts
|
|
8624
8691
|
var mesh_events_exports = {};
|
|
8625
8692
|
__export(mesh_events_exports, {
|
|
@@ -8630,10 +8697,11 @@ __export(mesh_events_exports, {
|
|
|
8630
8697
|
getPendingMeshCoordinatorEvents: () => getPendingMeshCoordinatorEvents,
|
|
8631
8698
|
handleMeshForwardEvent: () => handleMeshForwardEvent,
|
|
8632
8699
|
isMeshCoordinatorEvent: () => isMeshCoordinatorEvent,
|
|
8633
|
-
markMeshCoordinatorEventDirectDelivered: () => markMeshCoordinatorEventDirectDelivered,
|
|
8634
8700
|
queuePendingMeshCoordinatorEvent: () => queuePendingMeshCoordinatorEvent,
|
|
8635
8701
|
reconcileDirectDispatchCompletionFromTranscript: () => reconcileDirectDispatchCompletionFromTranscript,
|
|
8702
|
+
runMeshReconcileTick: () => runMeshReconcileTick,
|
|
8636
8703
|
setupMeshEventForwarding: () => setupMeshEventForwarding,
|
|
8704
|
+
setupMeshReconcileLoop: () => setupMeshReconcileLoop,
|
|
8637
8705
|
triggerMeshQueue: () => triggerMeshQueue,
|
|
8638
8706
|
tryAssignQueueTask: () => tryAssignQueueTask
|
|
8639
8707
|
});
|
|
@@ -8642,6 +8710,7 @@ var init_mesh_events = __esm({
|
|
|
8642
8710
|
"use strict";
|
|
8643
8711
|
init_mesh_events_pending();
|
|
8644
8712
|
init_mesh_events_stale();
|
|
8713
|
+
init_mesh_reconcile_loop();
|
|
8645
8714
|
init_mesh_events_coordinator();
|
|
8646
8715
|
}
|
|
8647
8716
|
});
|
|
@@ -32644,9 +32713,11 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
32644
32713
|
if (!this.generatingStartedAt) this.generatingStartedAt = now;
|
|
32645
32714
|
const modal = adapterStatus.activeModal;
|
|
32646
32715
|
LOG.info("CLI", `[${this.type}] approval modal: "${modal?.message?.slice(0, 80) ?? "none"}"`);
|
|
32716
|
+
const approvalEntrySeq = typeof adapterStatus?.approvalEntrySeq === "number" ? adapterStatus.approvalEntrySeq : 0;
|
|
32647
32717
|
const approvalFingerprint = JSON.stringify({
|
|
32648
32718
|
message: typeof modal?.message === "string" ? modal.message.trim() : "",
|
|
32649
|
-
buttons: Array.isArray(modal?.buttons) ? modal.buttons.map((button) => String(button).trim()) : []
|
|
32719
|
+
buttons: Array.isArray(modal?.buttons) ? modal.buttons.map((button) => String(button).trim()) : [],
|
|
32720
|
+
seq: approvalEntrySeq
|
|
32650
32721
|
});
|
|
32651
32722
|
if (approvalFingerprint !== this.lastApprovalEventFingerprint) {
|
|
32652
32723
|
this.lastApprovalEventFingerprint = approvalFingerprint;
|
|
@@ -32663,6 +32734,8 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
32663
32734
|
modalButtons: modal?.buttons
|
|
32664
32735
|
});
|
|
32665
32736
|
}
|
|
32737
|
+
} else if (newStatus === "generating" && this.lastStatus === "waiting_approval") {
|
|
32738
|
+
this.lastApprovalEventFingerprint = "";
|
|
32666
32739
|
} else if (newStatus === "idle" && (this.lastStatus === "generating" || this.lastStatus === "waiting_approval")) {
|
|
32667
32740
|
const duration = this.generatingStartedAt ? Math.round((now - this.generatingStartedAt) / 1e3) : 0;
|
|
32668
32741
|
if (!this.generatingStartedAt && !this.generatingDebouncePending) {
|
|
@@ -44578,18 +44651,6 @@ ${hintLines.join("\n")}` : "",
|
|
|
44578
44651
|
return { success: true };
|
|
44579
44652
|
}
|
|
44580
44653
|
case "launch_cli": {
|
|
44581
|
-
{
|
|
44582
|
-
const launchSettings = args?.settings && typeof args.settings === "object" ? args.settings : void 0;
|
|
44583
|
-
const isMeshWorkerLaunch = !!launchSettings && (readStringValue(launchSettings.meshNodeFor) || launchSettings.launchedByCoordinator === true);
|
|
44584
|
-
const hasCoordinatorDaemonId = !!launchSettings && !!readStringValue(launchSettings.meshCoordinatorDaemonId);
|
|
44585
|
-
if (launchSettings && isMeshWorkerLaunch && !hasCoordinatorDaemonId) {
|
|
44586
|
-
try {
|
|
44587
|
-
const localDaemonId = readStringValue(loadConfig().machineId);
|
|
44588
|
-
if (localDaemonId) launchSettings.meshCoordinatorDaemonId = localDaemonId;
|
|
44589
|
-
} catch {
|
|
44590
|
-
}
|
|
44591
|
-
}
|
|
44592
|
-
}
|
|
44593
44654
|
const launchResult = await this.deps.cliManager.handleCliCommand(cmd, args);
|
|
44594
44655
|
const meshNodeId = readStringValue(args?.settings?.meshNodeId);
|
|
44595
44656
|
const meshId = readStringValue(args?.settings?.meshNodeFor);
|
|
@@ -47251,6 +47312,8 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
47251
47312
|
nodes: mesh.nodes || [],
|
|
47252
47313
|
liveSessionRecords: liveMeshSessions
|
|
47253
47314
|
});
|
|
47315
|
+
const { getMeshStatusMissionSummaries: getMeshStatusMissionSummaries2 } = await Promise.resolve().then(() => (init_mesh_missions(), mesh_missions_exports));
|
|
47316
|
+
const missions = getMeshStatusMissionSummaries2(meshId);
|
|
47254
47317
|
const statusResult = {
|
|
47255
47318
|
success: true,
|
|
47256
47319
|
meshId: mesh.id,
|
|
@@ -47289,6 +47352,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
47289
47352
|
nodes: nodeStatuses,
|
|
47290
47353
|
queue: { tasks: queue, summary: queueSummary },
|
|
47291
47354
|
ledger: { entries: ledgerEntries, summary: ledgerSummary },
|
|
47355
|
+
...missions.length > 0 ? { missions } : {},
|
|
47292
47356
|
...asyncRefineJobs.length > 0 ? { asyncRefineJobs } : {},
|
|
47293
47357
|
...historicalSessions ? { historicalSessions } : {},
|
|
47294
47358
|
...pendingCoordinatorEvents.length > 0 ? { pendingCoordinatorEvents } : {},
|
|
@@ -55434,6 +55498,7 @@ var SessionRegistry = class {
|
|
|
55434
55498
|
init_logger();
|
|
55435
55499
|
init_config();
|
|
55436
55500
|
init_mesh_events();
|
|
55501
|
+
init_mesh_reconcile_loop();
|
|
55437
55502
|
|
|
55438
55503
|
// src/boot/process-hardening.ts
|
|
55439
55504
|
var _hardened = false;
|
|
@@ -55635,6 +55700,7 @@ async function initDaemonComponents(config) {
|
|
|
55635
55700
|
onMeshCoordinatorEventForwarded: config.onMeshCoordinatorEventForwarded
|
|
55636
55701
|
};
|
|
55637
55702
|
setupMeshEventForwarding(components);
|
|
55703
|
+
components.meshReconcileLoop = setupMeshReconcileLoop(components);
|
|
55638
55704
|
setImmediate(() => void router.resumePendingRefineJobsOnStartup());
|
|
55639
55705
|
return components;
|
|
55640
55706
|
}
|
|
@@ -55660,10 +55726,15 @@ async function shutdownDaemonComponents(components) {
|
|
|
55660
55726
|
agentStreamManager,
|
|
55661
55727
|
cliManager,
|
|
55662
55728
|
instanceManager,
|
|
55663
|
-
cdpManagers
|
|
55729
|
+
cdpManagers,
|
|
55730
|
+
meshReconcileLoop
|
|
55664
55731
|
} = components;
|
|
55665
55732
|
poller.stop();
|
|
55666
55733
|
cdpInitializer.stop();
|
|
55734
|
+
try {
|
|
55735
|
+
meshReconcileLoop?.stop();
|
|
55736
|
+
} catch {
|
|
55737
|
+
}
|
|
55667
55738
|
try {
|
|
55668
55739
|
if (agentStreamManager) {
|
|
55669
55740
|
await agentStreamManager.dispose(cdpManagers);
|