@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
package/dist/index.mjs
CHANGED
|
@@ -270,10 +270,10 @@ function readInjected(value) {
|
|
|
270
270
|
}
|
|
271
271
|
function getDaemonBuildInfo() {
|
|
272
272
|
if (cached) return cached;
|
|
273
|
-
const commit = readInjected(true ? "
|
|
274
|
-
const commitShort = readInjected(true ? "
|
|
275
|
-
const version = readInjected(true ? "0.9.82-rc.
|
|
276
|
-
const builtAt = readInjected(true ? "2026-06-
|
|
273
|
+
const commit = readInjected(true ? "89d1ac61612c1dfe7fac53be61ec5dbfa67d00b2" : void 0) ?? "unknown";
|
|
274
|
+
const commitShort = readInjected(true ? "89d1ac61" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
275
|
+
const version = readInjected(true ? "0.9.82-rc.274" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
276
|
+
const builtAt = readInjected(true ? "2026-06-15T07:04:52.710Z" : void 0);
|
|
277
277
|
cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
|
|
278
278
|
return cached;
|
|
279
279
|
}
|
|
@@ -4378,6 +4378,7 @@ __export(mesh_missions_exports, {
|
|
|
4378
4378
|
getActiveMeshMissionSummaries: () => getActiveMeshMissionSummaries,
|
|
4379
4379
|
getMeshMission: () => getMeshMission,
|
|
4380
4380
|
getMeshMissions: () => getMeshMissions,
|
|
4381
|
+
getMeshStatusMissionSummaries: () => getMeshStatusMissionSummaries,
|
|
4381
4382
|
summarizeMeshMission: () => summarizeMeshMission,
|
|
4382
4383
|
summarizeMissionTasks: () => summarizeMissionTasks,
|
|
4383
4384
|
upsertMeshMission: () => upsertMeshMission
|
|
@@ -4444,6 +4445,13 @@ function summarizeMeshMission(meshId, mission) {
|
|
|
4444
4445
|
function getActiveMeshMissionSummaries(meshId) {
|
|
4445
4446
|
return getMeshMissions(meshId, ["active"]).map((mission) => summarizeMeshMission(meshId, mission));
|
|
4446
4447
|
}
|
|
4448
|
+
function getMeshStatusMissionSummaries(meshId, options) {
|
|
4449
|
+
const historyLimit = Math.max(0, options?.historyLimit ?? 10);
|
|
4450
|
+
const all = getMeshMissions(meshId);
|
|
4451
|
+
const live = all.filter((m) => m.status === "active" || m.status === "paused");
|
|
4452
|
+
const history = all.filter((m) => m.status === "completed" || m.status === "abandoned").sort((a, b) => (b.updatedAt || "").localeCompare(a.updatedAt || "")).slice(0, historyLimit);
|
|
4453
|
+
return [...live, ...history].map((mission) => summarizeMeshMission(meshId, mission));
|
|
4454
|
+
}
|
|
4447
4455
|
function buildMissionPromptSection(meshId) {
|
|
4448
4456
|
const summaries = getActiveMeshMissionSummaries(meshId);
|
|
4449
4457
|
if (summaries.length === 0) return "";
|
|
@@ -6154,16 +6162,6 @@ function readNonEmptyString2(value) {
|
|
|
6154
6162
|
function readRecord3(value) {
|
|
6155
6163
|
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
6156
6164
|
}
|
|
6157
|
-
function canonicalDaemonId(value) {
|
|
6158
|
-
const id = readNonEmptyString2(value);
|
|
6159
|
-
if (!id) return "";
|
|
6160
|
-
return id.replace(/^(?:daemon|standalone)_/, "");
|
|
6161
|
-
}
|
|
6162
|
-
function sameDaemonId(a, b) {
|
|
6163
|
-
const ca = canonicalDaemonId(a);
|
|
6164
|
-
const cb = canonicalDaemonId(b);
|
|
6165
|
-
return ca !== "" && ca === cb;
|
|
6166
|
-
}
|
|
6167
6165
|
function buildMeshWorkerRelayStamp(currentSettings, meshContext) {
|
|
6168
6166
|
if (!meshContext) return void 0;
|
|
6169
6167
|
const settings = currentSettings && typeof currentSettings === "object" ? currentSettings : {};
|
|
@@ -6367,29 +6365,6 @@ function buildPendingEventFingerprint(event) {
|
|
|
6367
6365
|
timestamp || ""
|
|
6368
6366
|
].join("::");
|
|
6369
6367
|
}
|
|
6370
|
-
function markMeshCoordinatorEventDirectDelivered(coordinatorDaemonId, event) {
|
|
6371
|
-
const canonical = canonicalDaemonId(coordinatorDaemonId);
|
|
6372
|
-
if (!canonical) return;
|
|
6373
|
-
const fingerprint = buildPendingEventFingerprint(event);
|
|
6374
|
-
if (!fingerprint.trim()) return;
|
|
6375
|
-
try {
|
|
6376
|
-
const store = MeshRuntimeStore.getInstance();
|
|
6377
|
-
store.recordDirectDelivered(canonical, fingerprint, DIRECT_DELIVERED_TTL_MS);
|
|
6378
|
-
store.sweepExpiredDirectDelivered();
|
|
6379
|
-
} catch {
|
|
6380
|
-
}
|
|
6381
|
-
}
|
|
6382
|
-
function wasDirectDeliveredToCoordinator(coordinatorDaemonId, event) {
|
|
6383
|
-
const canonical = canonicalDaemonId(coordinatorDaemonId);
|
|
6384
|
-
if (!canonical) return false;
|
|
6385
|
-
const fingerprint = buildPendingEventFingerprint(event);
|
|
6386
|
-
if (!fingerprint.trim()) return false;
|
|
6387
|
-
try {
|
|
6388
|
-
return MeshRuntimeStore.getInstance().wasDirectDelivered(canonical, fingerprint);
|
|
6389
|
-
} catch {
|
|
6390
|
-
return false;
|
|
6391
|
-
}
|
|
6392
|
-
}
|
|
6393
6368
|
function hasPendingCoordinatorEventDuplicate(event) {
|
|
6394
6369
|
const fingerprint = buildPendingEventFingerprint(event);
|
|
6395
6370
|
if (!fingerprint.trim()) return false;
|
|
@@ -6588,9 +6563,7 @@ function drainPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
|
|
|
6588
6563
|
for (const event of filtered) pushUnique(event);
|
|
6589
6564
|
}
|
|
6590
6565
|
if (merged.length === 0) return [];
|
|
6591
|
-
|
|
6592
|
-
if (deliverable.length === 0) return [];
|
|
6593
|
-
return reconcilePendingMeshCoordinatorEvents(meshId, deliverable);
|
|
6566
|
+
return reconcilePendingMeshCoordinatorEvents(meshId, merged);
|
|
6594
6567
|
}
|
|
6595
6568
|
function getPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
|
|
6596
6569
|
if (!meshId) return [];
|
|
@@ -6617,8 +6590,7 @@ function getPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
|
|
|
6617
6590
|
for (const event of readPendingMeshCoordinatorEventsFromDisk(meshId, coordinatorDaemonId)) {
|
|
6618
6591
|
pushUnique(event);
|
|
6619
6592
|
}
|
|
6620
|
-
|
|
6621
|
-
return reconcilePendingMeshCoordinatorEvents(meshId, deliverable);
|
|
6593
|
+
return reconcilePendingMeshCoordinatorEvents(meshId, merged);
|
|
6622
6594
|
}
|
|
6623
6595
|
function clearPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
|
|
6624
6596
|
if (!meshId) return;
|
|
@@ -6634,7 +6606,7 @@ function clearPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
|
|
|
6634
6606
|
}
|
|
6635
6607
|
}
|
|
6636
6608
|
}
|
|
6637
|
-
var REFINE_TERMINAL_EVENTS,
|
|
6609
|
+
var REFINE_TERMINAL_EVENTS, MAX_PENDING_EVENTS_BYTES, MAX_PENDING_EVENTS_KEEP;
|
|
6638
6610
|
var init_mesh_events_pending = __esm({
|
|
6639
6611
|
"src/mesh/mesh-events-pending.ts"() {
|
|
6640
6612
|
"use strict";
|
|
@@ -6643,7 +6615,6 @@ var init_mesh_events_pending = __esm({
|
|
|
6643
6615
|
init_mesh_runtime_store();
|
|
6644
6616
|
init_mesh_events_utils();
|
|
6645
6617
|
REFINE_TERMINAL_EVENTS = /* @__PURE__ */ new Set(["refine:completed", "refine:failed"]);
|
|
6646
|
-
DIRECT_DELIVERED_TTL_MS = 10 * 60 * 1e3;
|
|
6647
6618
|
MAX_PENDING_EVENTS_BYTES = 100 * 1024;
|
|
6648
6619
|
MAX_PENDING_EVENTS_KEEP = 50;
|
|
6649
6620
|
}
|
|
@@ -8005,7 +7976,6 @@ function injectMeshSystemMessage(components, args) {
|
|
|
8005
7976
|
const workerCoordinatorDaemonId = readNonEmptyString2(
|
|
8006
7977
|
sourceSession?.getState()?.settings?.meshCoordinatorDaemonId
|
|
8007
7978
|
);
|
|
8008
|
-
const localDaemonId = readNonEmptyString2(loadConfig().machineId);
|
|
8009
7979
|
if (components.onMeshCoordinatorEventForwarded) {
|
|
8010
7980
|
try {
|
|
8011
7981
|
components.onMeshCoordinatorEventForwarded({
|
|
@@ -8360,60 +8330,6 @@ function injectMeshSystemMessage(components, args) {
|
|
|
8360
8330
|
recoveryContext
|
|
8361
8331
|
});
|
|
8362
8332
|
if (!messageText) return { success: false, error: "unsupported mesh event" };
|
|
8363
|
-
const coordinatorInstances = components.instanceManager.getByCategory("cli").filter((inst) => {
|
|
8364
|
-
const instState = inst.getState();
|
|
8365
|
-
if (instState.settings?.meshCoordinatorFor !== args.meshId) return false;
|
|
8366
|
-
if (args.sourceInstanceId && instState.instanceId === args.sourceInstanceId) return false;
|
|
8367
|
-
if (workerCoordinatorDaemonId && localDaemonId && !sameDaemonId(workerCoordinatorDaemonId, localDaemonId)) return false;
|
|
8368
|
-
return true;
|
|
8369
|
-
});
|
|
8370
|
-
if (coordinatorInstances.length === 0) {
|
|
8371
|
-
const remoteCoordinatorDaemonId = workerCoordinatorDaemonId && localDaemonId && !sameDaemonId(workerCoordinatorDaemonId, localDaemonId) ? workerCoordinatorDaemonId : "";
|
|
8372
|
-
if (remoteCoordinatorDaemonId && components.dispatchMeshCommand) {
|
|
8373
|
-
const forwardPayload = {
|
|
8374
|
-
event: args.event,
|
|
8375
|
-
meshId: args.meshId,
|
|
8376
|
-
nodeId: args.nodeId || void 0,
|
|
8377
|
-
workspace: readNonEmptyString2(args.metadataEvent.workspace),
|
|
8378
|
-
...args.metadataEvent,
|
|
8379
|
-
...recoveryContext ? { recoveryContext } : {}
|
|
8380
|
-
};
|
|
8381
|
-
components.dispatchMeshCommand(remoteCoordinatorDaemonId, "mesh_forward_event", forwardPayload).then(() => {
|
|
8382
|
-
LOG.info("MeshEvents", `Forwarded ${args.event} for mesh ${args.meshId} to remote coordinator daemon ${remoteCoordinatorDaemonId.slice(0, 12)}\u2026`);
|
|
8383
|
-
}).catch((error) => {
|
|
8384
|
-
LOG.warn("MeshEvents", `Remote forward of ${args.event} failed (${error?.message || error}); queuing for backfill`);
|
|
8385
|
-
queuePendingMeshCoordinatorEvent({
|
|
8386
|
-
event: args.event,
|
|
8387
|
-
meshId: args.meshId,
|
|
8388
|
-
nodeLabel: args.nodeLabel,
|
|
8389
|
-
nodeId: args.nodeId || void 0,
|
|
8390
|
-
workspace: readNonEmptyString2(args.metadataEvent.workspace),
|
|
8391
|
-
metadataEvent: { ...args.metadataEvent, ...recoveryContext ? { recoveryContext } : {} },
|
|
8392
|
-
coordinatorMessage: messageText,
|
|
8393
|
-
queuedAt: Date.now(),
|
|
8394
|
-
targetCoordinatorDaemonId: remoteCoordinatorDaemonId
|
|
8395
|
-
});
|
|
8396
|
-
});
|
|
8397
|
-
return { success: true, forwarded: 0, remoteForwarded: true };
|
|
8398
|
-
}
|
|
8399
|
-
if (queuePendingMeshCoordinatorEvent({
|
|
8400
|
-
event: args.event,
|
|
8401
|
-
meshId: args.meshId,
|
|
8402
|
-
nodeLabel: args.nodeLabel,
|
|
8403
|
-
nodeId: args.nodeId || void 0,
|
|
8404
|
-
workspace: readNonEmptyString2(args.metadataEvent.workspace),
|
|
8405
|
-
metadataEvent: {
|
|
8406
|
-
...args.metadataEvent,
|
|
8407
|
-
...recoveryContext ? { recoveryContext } : {}
|
|
8408
|
-
},
|
|
8409
|
-
coordinatorMessage: messageText,
|
|
8410
|
-
queuedAt: Date.now(),
|
|
8411
|
-
...workerCoordinatorDaemonId ? { targetCoordinatorDaemonId: workerCoordinatorDaemonId } : {}
|
|
8412
|
-
})) {
|
|
8413
|
-
LOG.info("MeshEvents", `Queued ${args.event} for MCP coordinator (mesh ${args.meshId}${workerCoordinatorDaemonId ? `, coordinator daemon ${workerCoordinatorDaemonId}` : ""})`);
|
|
8414
|
-
}
|
|
8415
|
-
return { success: true, forwarded: 0 };
|
|
8416
|
-
}
|
|
8417
8333
|
const pendingEvent = {
|
|
8418
8334
|
event: args.event,
|
|
8419
8335
|
meshId: args.meshId,
|
|
@@ -8429,21 +8345,9 @@ function injectMeshSystemMessage(components, args) {
|
|
|
8429
8345
|
...workerCoordinatorDaemonId ? { targetCoordinatorDaemonId: workerCoordinatorDaemonId } : {}
|
|
8430
8346
|
};
|
|
8431
8347
|
if (queuePendingMeshCoordinatorEvent(pendingEvent)) {
|
|
8432
|
-
LOG.info("MeshEvents", `Queued ${args.event} for
|
|
8433
|
-
}
|
|
8434
|
-
if (localDaemonId) {
|
|
8435
|
-
markMeshCoordinatorEventDirectDelivered(localDaemonId, pendingEvent);
|
|
8436
|
-
}
|
|
8437
|
-
const forceInject = shouldForceInjectMeshEvent(args.event);
|
|
8438
|
-
for (const coord of coordinatorInstances) {
|
|
8439
|
-
const coordState = coord.getState();
|
|
8440
|
-
LOG.info("MeshEvents", `Forwarding mesh event to coordinator ${coordState.instanceId}${forceInject ? " (force)" : ""}`);
|
|
8441
|
-
coord.onEvent("send_message", {
|
|
8442
|
-
input: { text: messageText, textFallback: messageText },
|
|
8443
|
-
...forceInject ? { force: true } : {}
|
|
8444
|
-
});
|
|
8348
|
+
LOG.info("MeshEvents", `Queued ${args.event} for coordinator (mesh ${args.meshId}${workerCoordinatorDaemonId ? `, coordinator daemon ${workerCoordinatorDaemonId}` : ""})`);
|
|
8445
8349
|
}
|
|
8446
|
-
return { success: true, forwarded:
|
|
8350
|
+
return { success: true, forwarded: 0 };
|
|
8447
8351
|
}
|
|
8448
8352
|
function handleMeshForwardEvent(components, payload) {
|
|
8449
8353
|
const eventName = readNonEmptyString2(payload.event);
|
|
@@ -8613,6 +8517,169 @@ var init_mesh_events_coordinator = __esm({
|
|
|
8613
8517
|
}
|
|
8614
8518
|
});
|
|
8615
8519
|
|
|
8520
|
+
// src/mesh/mesh-reconcile-loop.ts
|
|
8521
|
+
function resolveReconcileIntervalMs() {
|
|
8522
|
+
const raw = readNonEmptyString2(process.env.MESH_RECONCILE_INTERVAL_MS);
|
|
8523
|
+
if (raw) {
|
|
8524
|
+
const parsed = Number.parseInt(raw, 10);
|
|
8525
|
+
if (Number.isFinite(parsed) && parsed >= 1e3 && parsed <= 6e4) return parsed;
|
|
8526
|
+
}
|
|
8527
|
+
return DEFAULT_RECONCILE_INTERVAL_MS;
|
|
8528
|
+
}
|
|
8529
|
+
function findLiveCoordinators(components) {
|
|
8530
|
+
const out = [];
|
|
8531
|
+
for (const inst of components.instanceManager.getByCategory("cli")) {
|
|
8532
|
+
const state = inst.getState();
|
|
8533
|
+
const settings = state.settings && typeof state.settings === "object" ? state.settings : {};
|
|
8534
|
+
const meshId = readNonEmptyString2(settings.meshCoordinatorFor);
|
|
8535
|
+
if (!meshId) continue;
|
|
8536
|
+
const status = readNonEmptyString2(state.status).toLowerCase();
|
|
8537
|
+
out.push({ meshId, instance: inst, idle: status === "idle" });
|
|
8538
|
+
}
|
|
8539
|
+
return out;
|
|
8540
|
+
}
|
|
8541
|
+
function injectPendingIntoCoordinator(coordinator, pending) {
|
|
8542
|
+
if (!coordinator || !pending.coordinatorMessage) return;
|
|
8543
|
+
const force = shouldForceInjectMeshEvent(pending.event);
|
|
8544
|
+
coordinator.onEvent("send_message", {
|
|
8545
|
+
input: { text: pending.coordinatorMessage, textFallback: pending.coordinatorMessage },
|
|
8546
|
+
...force ? { force: true } : {}
|
|
8547
|
+
});
|
|
8548
|
+
}
|
|
8549
|
+
async function runMeshReconcileTick(components) {
|
|
8550
|
+
const coordinators = findLiveCoordinators(components);
|
|
8551
|
+
if (coordinators.length === 0) {
|
|
8552
|
+
return;
|
|
8553
|
+
}
|
|
8554
|
+
const byMesh = /* @__PURE__ */ new Map();
|
|
8555
|
+
for (const c of coordinators) {
|
|
8556
|
+
const list = byMesh.get(c.meshId);
|
|
8557
|
+
if (list) list.push(c);
|
|
8558
|
+
else byMesh.set(c.meshId, [c]);
|
|
8559
|
+
}
|
|
8560
|
+
const localDaemonId = readNonEmptyString2(loadConfig().machineId) || void 0;
|
|
8561
|
+
const dispatchMeshCommand = components.dispatchMeshCommand;
|
|
8562
|
+
const store = (() => {
|
|
8563
|
+
try {
|
|
8564
|
+
return MeshRuntimeStore.getInstance();
|
|
8565
|
+
} catch {
|
|
8566
|
+
return void 0;
|
|
8567
|
+
}
|
|
8568
|
+
})();
|
|
8569
|
+
for (const [meshId, meshCoordinators] of byMesh) {
|
|
8570
|
+
if (dispatchMeshCommand) {
|
|
8571
|
+
try {
|
|
8572
|
+
await pullRemoteNodeQueues(components, meshId, localDaemonId);
|
|
8573
|
+
} catch (e) {
|
|
8574
|
+
LOG.warn("MeshReconcile", `Remote node pull failed for mesh ${meshId}: ${e?.message || e}`);
|
|
8575
|
+
}
|
|
8576
|
+
}
|
|
8577
|
+
const idleCoordinators = meshCoordinators.filter((c) => c.idle);
|
|
8578
|
+
if (idleCoordinators.length === 0) continue;
|
|
8579
|
+
if (store) {
|
|
8580
|
+
try {
|
|
8581
|
+
if (store.pendingEventCount(meshId) === 0) continue;
|
|
8582
|
+
} catch {
|
|
8583
|
+
}
|
|
8584
|
+
}
|
|
8585
|
+
let pendingEvents = [];
|
|
8586
|
+
try {
|
|
8587
|
+
pendingEvents = drainPendingMeshCoordinatorEvents(meshId, localDaemonId);
|
|
8588
|
+
} catch (e) {
|
|
8589
|
+
LOG.warn("MeshReconcile", `Drain failed for mesh ${meshId}: ${e?.message || e}`);
|
|
8590
|
+
continue;
|
|
8591
|
+
}
|
|
8592
|
+
if (pendingEvents.length === 0) continue;
|
|
8593
|
+
LOG.info("MeshReconcile", `Reconcile inject: ${pendingEvents.length} pending event(s) \u2192 ${idleCoordinators.length} idle coordinator(s) for mesh ${meshId}`);
|
|
8594
|
+
for (const pending of pendingEvents) {
|
|
8595
|
+
for (const c of idleCoordinators) {
|
|
8596
|
+
injectPendingIntoCoordinator(c.instance, pending);
|
|
8597
|
+
}
|
|
8598
|
+
}
|
|
8599
|
+
}
|
|
8600
|
+
}
|
|
8601
|
+
async function pullRemoteNodeQueues(components, meshId, localDaemonId) {
|
|
8602
|
+
const dispatchMeshCommand = components.dispatchMeshCommand;
|
|
8603
|
+
if (!dispatchMeshCommand) return;
|
|
8604
|
+
const mesh = listMeshes().find((m) => m.id === meshId);
|
|
8605
|
+
if (!mesh) return;
|
|
8606
|
+
const pendingEventArgs = {
|
|
8607
|
+
meshId,
|
|
8608
|
+
...localDaemonId ? { coordinatorDaemonId: localDaemonId } : {}
|
|
8609
|
+
};
|
|
8610
|
+
for (const node of mesh.nodes) {
|
|
8611
|
+
const nodeDaemonId = readNonEmptyString2(node.daemonId);
|
|
8612
|
+
if (!nodeDaemonId) continue;
|
|
8613
|
+
if (localDaemonId && nodeDaemonId === localDaemonId) continue;
|
|
8614
|
+
let events;
|
|
8615
|
+
try {
|
|
8616
|
+
events = await dispatchMeshCommand(nodeDaemonId, "get_pending_mesh_events", pendingEventArgs);
|
|
8617
|
+
} catch {
|
|
8618
|
+
continue;
|
|
8619
|
+
}
|
|
8620
|
+
const list = extractPendingEvents(events).filter((e) => readNonEmptyString2(e?.meshId) === meshId);
|
|
8621
|
+
for (const event of list) {
|
|
8622
|
+
const payload = buildForwardPayloadFromPending(event);
|
|
8623
|
+
if (!payload.event || !payload.meshId) continue;
|
|
8624
|
+
try {
|
|
8625
|
+
handleMeshForwardEvent(components, payload);
|
|
8626
|
+
} catch {
|
|
8627
|
+
}
|
|
8628
|
+
}
|
|
8629
|
+
}
|
|
8630
|
+
}
|
|
8631
|
+
function extractPendingEvents(raw) {
|
|
8632
|
+
if (Array.isArray(raw)) return raw;
|
|
8633
|
+
if (raw && typeof raw === "object") {
|
|
8634
|
+
const events = raw.events;
|
|
8635
|
+
if (Array.isArray(events)) return events;
|
|
8636
|
+
}
|
|
8637
|
+
return [];
|
|
8638
|
+
}
|
|
8639
|
+
function buildForwardPayloadFromPending(event) {
|
|
8640
|
+
const metadata = event?.metadataEvent && typeof event.metadataEvent === "object" ? event.metadataEvent : {};
|
|
8641
|
+
return {
|
|
8642
|
+
event: readNonEmptyString2(event?.event),
|
|
8643
|
+
meshId: readNonEmptyString2(event?.meshId),
|
|
8644
|
+
nodeId: readNonEmptyString2(event?.nodeId) || readNonEmptyString2(metadata.meshNodeId),
|
|
8645
|
+
workspace: readNonEmptyString2(event?.workspace) || readNonEmptyString2(metadata.workspace),
|
|
8646
|
+
...metadata
|
|
8647
|
+
};
|
|
8648
|
+
}
|
|
8649
|
+
function setupMeshReconcileLoop(components) {
|
|
8650
|
+
const intervalMs = resolveReconcileIntervalMs();
|
|
8651
|
+
let running = false;
|
|
8652
|
+
const timer = setInterval(() => {
|
|
8653
|
+
if (running) return;
|
|
8654
|
+
running = true;
|
|
8655
|
+
void runMeshReconcileTick(components).catch((e) => LOG.warn("MeshReconcile", `Reconcile tick error: ${e?.message || e}`)).finally(() => {
|
|
8656
|
+
running = false;
|
|
8657
|
+
});
|
|
8658
|
+
}, intervalMs);
|
|
8659
|
+
if (typeof timer.unref === "function") timer.unref();
|
|
8660
|
+
LOG.info("MeshReconcile", `Mesh reconcile loop started (interval ${intervalMs}ms)`);
|
|
8661
|
+
return {
|
|
8662
|
+
stop() {
|
|
8663
|
+
clearInterval(timer);
|
|
8664
|
+
LOG.info("MeshReconcile", "Mesh reconcile loop stopped");
|
|
8665
|
+
}
|
|
8666
|
+
};
|
|
8667
|
+
}
|
|
8668
|
+
var DEFAULT_RECONCILE_INTERVAL_MS;
|
|
8669
|
+
var init_mesh_reconcile_loop = __esm({
|
|
8670
|
+
"src/mesh/mesh-reconcile-loop.ts"() {
|
|
8671
|
+
"use strict";
|
|
8672
|
+
init_config();
|
|
8673
|
+
init_mesh_config();
|
|
8674
|
+
init_logger();
|
|
8675
|
+
init_mesh_events_pending();
|
|
8676
|
+
init_mesh_runtime_store();
|
|
8677
|
+
init_mesh_events_coordinator();
|
|
8678
|
+
init_mesh_events_utils();
|
|
8679
|
+
DEFAULT_RECONCILE_INTERVAL_MS = 4e3;
|
|
8680
|
+
}
|
|
8681
|
+
});
|
|
8682
|
+
|
|
8616
8683
|
// src/mesh/mesh-events.ts
|
|
8617
8684
|
var mesh_events_exports = {};
|
|
8618
8685
|
__export(mesh_events_exports, {
|
|
@@ -8623,10 +8690,11 @@ __export(mesh_events_exports, {
|
|
|
8623
8690
|
getPendingMeshCoordinatorEvents: () => getPendingMeshCoordinatorEvents,
|
|
8624
8691
|
handleMeshForwardEvent: () => handleMeshForwardEvent,
|
|
8625
8692
|
isMeshCoordinatorEvent: () => isMeshCoordinatorEvent,
|
|
8626
|
-
markMeshCoordinatorEventDirectDelivered: () => markMeshCoordinatorEventDirectDelivered,
|
|
8627
8693
|
queuePendingMeshCoordinatorEvent: () => queuePendingMeshCoordinatorEvent,
|
|
8628
8694
|
reconcileDirectDispatchCompletionFromTranscript: () => reconcileDirectDispatchCompletionFromTranscript,
|
|
8695
|
+
runMeshReconcileTick: () => runMeshReconcileTick,
|
|
8629
8696
|
setupMeshEventForwarding: () => setupMeshEventForwarding,
|
|
8697
|
+
setupMeshReconcileLoop: () => setupMeshReconcileLoop,
|
|
8630
8698
|
triggerMeshQueue: () => triggerMeshQueue,
|
|
8631
8699
|
tryAssignQueueTask: () => tryAssignQueueTask
|
|
8632
8700
|
});
|
|
@@ -8635,6 +8703,7 @@ var init_mesh_events = __esm({
|
|
|
8635
8703
|
"use strict";
|
|
8636
8704
|
init_mesh_events_pending();
|
|
8637
8705
|
init_mesh_events_stale();
|
|
8706
|
+
init_mesh_reconcile_loop();
|
|
8638
8707
|
init_mesh_events_coordinator();
|
|
8639
8708
|
}
|
|
8640
8709
|
});
|
|
@@ -32303,9 +32372,11 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
32303
32372
|
if (!this.generatingStartedAt) this.generatingStartedAt = now;
|
|
32304
32373
|
const modal = adapterStatus.activeModal;
|
|
32305
32374
|
LOG.info("CLI", `[${this.type}] approval modal: "${modal?.message?.slice(0, 80) ?? "none"}"`);
|
|
32375
|
+
const approvalEntrySeq = typeof adapterStatus?.approvalEntrySeq === "number" ? adapterStatus.approvalEntrySeq : 0;
|
|
32306
32376
|
const approvalFingerprint = JSON.stringify({
|
|
32307
32377
|
message: typeof modal?.message === "string" ? modal.message.trim() : "",
|
|
32308
|
-
buttons: Array.isArray(modal?.buttons) ? modal.buttons.map((button) => String(button).trim()) : []
|
|
32378
|
+
buttons: Array.isArray(modal?.buttons) ? modal.buttons.map((button) => String(button).trim()) : [],
|
|
32379
|
+
seq: approvalEntrySeq
|
|
32309
32380
|
});
|
|
32310
32381
|
if (approvalFingerprint !== this.lastApprovalEventFingerprint) {
|
|
32311
32382
|
this.lastApprovalEventFingerprint = approvalFingerprint;
|
|
@@ -32322,6 +32393,8 @@ var CliProviderInstance = class _CliProviderInstance {
|
|
|
32322
32393
|
modalButtons: modal?.buttons
|
|
32323
32394
|
});
|
|
32324
32395
|
}
|
|
32396
|
+
} else if (newStatus === "generating" && this.lastStatus === "waiting_approval") {
|
|
32397
|
+
this.lastApprovalEventFingerprint = "";
|
|
32325
32398
|
} else if (newStatus === "idle" && (this.lastStatus === "generating" || this.lastStatus === "waiting_approval")) {
|
|
32326
32399
|
const duration = this.generatingStartedAt ? Math.round((now - this.generatingStartedAt) / 1e3) : 0;
|
|
32327
32400
|
if (!this.generatingStartedAt && !this.generatingDebouncePending) {
|
|
@@ -44242,18 +44315,6 @@ ${hintLines.join("\n")}` : "",
|
|
|
44242
44315
|
return { success: true };
|
|
44243
44316
|
}
|
|
44244
44317
|
case "launch_cli": {
|
|
44245
|
-
{
|
|
44246
|
-
const launchSettings = args?.settings && typeof args.settings === "object" ? args.settings : void 0;
|
|
44247
|
-
const isMeshWorkerLaunch = !!launchSettings && (readStringValue(launchSettings.meshNodeFor) || launchSettings.launchedByCoordinator === true);
|
|
44248
|
-
const hasCoordinatorDaemonId = !!launchSettings && !!readStringValue(launchSettings.meshCoordinatorDaemonId);
|
|
44249
|
-
if (launchSettings && isMeshWorkerLaunch && !hasCoordinatorDaemonId) {
|
|
44250
|
-
try {
|
|
44251
|
-
const localDaemonId = readStringValue(loadConfig().machineId);
|
|
44252
|
-
if (localDaemonId) launchSettings.meshCoordinatorDaemonId = localDaemonId;
|
|
44253
|
-
} catch {
|
|
44254
|
-
}
|
|
44255
|
-
}
|
|
44256
|
-
}
|
|
44257
44318
|
const launchResult = await this.deps.cliManager.handleCliCommand(cmd, args);
|
|
44258
44319
|
const meshNodeId = readStringValue(args?.settings?.meshNodeId);
|
|
44259
44320
|
const meshId = readStringValue(args?.settings?.meshNodeFor);
|
|
@@ -46915,6 +46976,8 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
46915
46976
|
nodes: mesh.nodes || [],
|
|
46916
46977
|
liveSessionRecords: liveMeshSessions
|
|
46917
46978
|
});
|
|
46979
|
+
const { getMeshStatusMissionSummaries: getMeshStatusMissionSummaries2 } = await Promise.resolve().then(() => (init_mesh_missions(), mesh_missions_exports));
|
|
46980
|
+
const missions = getMeshStatusMissionSummaries2(meshId);
|
|
46918
46981
|
const statusResult = {
|
|
46919
46982
|
success: true,
|
|
46920
46983
|
meshId: mesh.id,
|
|
@@ -46953,6 +47016,7 @@ ${ptyResult.output.slice(-2e3)}`);
|
|
|
46953
47016
|
nodes: nodeStatuses,
|
|
46954
47017
|
queue: { tasks: queue, summary: queueSummary },
|
|
46955
47018
|
ledger: { entries: ledgerEntries, summary: ledgerSummary },
|
|
47019
|
+
...missions.length > 0 ? { missions } : {},
|
|
46956
47020
|
...asyncRefineJobs.length > 0 ? { asyncRefineJobs } : {},
|
|
46957
47021
|
...historicalSessions ? { historicalSessions } : {},
|
|
46958
47022
|
...pendingCoordinatorEvents.length > 0 ? { pendingCoordinatorEvents } : {},
|
|
@@ -55105,6 +55169,7 @@ var SessionRegistry = class {
|
|
|
55105
55169
|
init_logger();
|
|
55106
55170
|
init_config();
|
|
55107
55171
|
init_mesh_events();
|
|
55172
|
+
init_mesh_reconcile_loop();
|
|
55108
55173
|
|
|
55109
55174
|
// src/boot/process-hardening.ts
|
|
55110
55175
|
var _hardened = false;
|
|
@@ -55306,6 +55371,7 @@ async function initDaemonComponents(config) {
|
|
|
55306
55371
|
onMeshCoordinatorEventForwarded: config.onMeshCoordinatorEventForwarded
|
|
55307
55372
|
};
|
|
55308
55373
|
setupMeshEventForwarding(components);
|
|
55374
|
+
components.meshReconcileLoop = setupMeshReconcileLoop(components);
|
|
55309
55375
|
setImmediate(() => void router.resumePendingRefineJobsOnStartup());
|
|
55310
55376
|
return components;
|
|
55311
55377
|
}
|
|
@@ -55331,10 +55397,15 @@ async function shutdownDaemonComponents(components) {
|
|
|
55331
55397
|
agentStreamManager,
|
|
55332
55398
|
cliManager,
|
|
55333
55399
|
instanceManager,
|
|
55334
|
-
cdpManagers
|
|
55400
|
+
cdpManagers,
|
|
55401
|
+
meshReconcileLoop
|
|
55335
55402
|
} = components;
|
|
55336
55403
|
poller.stop();
|
|
55337
55404
|
cdpInitializer.stop();
|
|
55405
|
+
try {
|
|
55406
|
+
meshReconcileLoop?.stop();
|
|
55407
|
+
} catch {
|
|
55408
|
+
}
|
|
55338
55409
|
try {
|
|
55339
55410
|
if (agentStreamManager) {
|
|
55340
55411
|
await agentStreamManager.dispose(cdpManagers);
|