@adhdev/daemon-core 0.9.82-rc.275 → 0.9.82-rc.276
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 +1 -0
- package/dist/index.js +59 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -21
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/mesh-events-pending.d.ts +2 -2
- package/dist/mesh/mesh-runtime-store.d.ts +2 -2
- package/package.json +2 -2
- package/src/boot/daemon-lifecycle.ts +9 -0
- package/src/mesh/mesh-events-coordinator.ts +20 -2
- package/src/mesh/mesh-events-pending.ts +48 -15
- package/src/mesh/mesh-reconcile-loop.ts +23 -1
- package/src/mesh/mesh-runtime-store.ts +21 -8
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 ? "746fc68e4c297b988b76207bb8c63ab6062a38e1" : void 0) ?? "unknown";
|
|
274
|
+
const commitShort = readInjected(true ? "746fc68e" : void 0) ?? (commit !== "unknown" ? commit.slice(0, 7) : "unknown");
|
|
275
|
+
const version = readInjected(true ? "0.9.82-rc.276" : void 0) ?? readInjected(typeof process !== "undefined" ? process.env?.ADHDEV_PKG_VERSION : void 0) ?? "unknown";
|
|
276
|
+
const builtAt = readInjected(true ? "2026-06-15T09:29:09.895Z" : void 0);
|
|
277
277
|
cached = builtAt ? { commit, commitShort, version, builtAt } : { commit, commitShort, version };
|
|
278
278
|
return cached;
|
|
279
279
|
}
|
|
@@ -4273,11 +4273,12 @@ var init_mesh_runtime_store = __esm({
|
|
|
4273
4273
|
const onlyEvents = opts?.onlyEvents;
|
|
4274
4274
|
if (onlyEvents && onlyEvents.size === 0) return [];
|
|
4275
4275
|
const eventList = onlyEvents ? [...onlyEvents] : [];
|
|
4276
|
+
const daemonIds = (Array.isArray(coordinatorDaemonId) ? coordinatorDaemonId : coordinatorDaemonId ? [coordinatorDaemonId] : []).filter((id) => typeof id === "string" && id.length > 0);
|
|
4276
4277
|
const clauses = ["mesh_id = ?", "drained = 0"];
|
|
4277
4278
|
const params = [meshId];
|
|
4278
|
-
if (
|
|
4279
|
-
clauses.push(
|
|
4280
|
-
params.push(
|
|
4279
|
+
if (daemonIds.length > 0) {
|
|
4280
|
+
clauses.push(`(coordinator_daemon_id IS NULL OR coordinator_daemon_id IN (${daemonIds.map(() => "?").join(",")}))`);
|
|
4281
|
+
params.push(...daemonIds);
|
|
4281
4282
|
}
|
|
4282
4283
|
if (eventList.length > 0) {
|
|
4283
4284
|
clauses.push(`event IN (${eventList.map(() => "?").join(",")})`);
|
|
@@ -4307,8 +4308,9 @@ var init_mesh_runtime_store = __esm({
|
|
|
4307
4308
|
}
|
|
4308
4309
|
/** Non-destructive peek — returns undrained events without marking them drained. */
|
|
4309
4310
|
peekPendingEvents(meshId, coordinatorDaemonId) {
|
|
4310
|
-
const
|
|
4311
|
-
const
|
|
4311
|
+
const daemonIds = (Array.isArray(coordinatorDaemonId) ? coordinatorDaemonId : coordinatorDaemonId ? [coordinatorDaemonId] : []).filter((id) => typeof id === "string" && id.length > 0);
|
|
4312
|
+
const whereClause = daemonIds.length > 0 ? `WHERE mesh_id = ? AND drained = 0 AND (coordinator_daemon_id IS NULL OR coordinator_daemon_id IN (${daemonIds.map(() => "?").join(",")}))` : `WHERE mesh_id = ? AND drained = 0`;
|
|
4313
|
+
const params = daemonIds.length > 0 ? [meshId, ...daemonIds] : [meshId];
|
|
4312
4314
|
const rows = this.db.prepare(
|
|
4313
4315
|
`SELECT id, event, payload FROM mesh_pending_events ${whereClause} ORDER BY queued_at ASC LIMIT 100`
|
|
4314
4316
|
).all(...params);
|
|
@@ -6351,6 +6353,19 @@ var init_mesh_events_utils = __esm({
|
|
|
6351
6353
|
import { appendFileSync as appendFileSync2, existsSync as existsSync12, readFileSync as readFileSync10, renameSync as renameSync4, statSync as statSync5, unlinkSync as unlinkSync2, writeFileSync as writeFileSync6 } from "fs";
|
|
6352
6354
|
import { join as join13 } from "path";
|
|
6353
6355
|
import { randomUUID as randomUUID7 } from "crypto";
|
|
6356
|
+
function normalizeCoordinatorDaemonIds(coordinatorDaemonId) {
|
|
6357
|
+
const raw = Array.isArray(coordinatorDaemonId) ? coordinatorDaemonId : coordinatorDaemonId != null ? [coordinatorDaemonId] : [];
|
|
6358
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6359
|
+
const out = [];
|
|
6360
|
+
for (const id of raw) {
|
|
6361
|
+
if (typeof id !== "string") continue;
|
|
6362
|
+
const trimmed = id.trim();
|
|
6363
|
+
if (!trimmed || seen.has(trimmed)) continue;
|
|
6364
|
+
seen.add(trimmed);
|
|
6365
|
+
out.push(trimmed);
|
|
6366
|
+
}
|
|
6367
|
+
return out;
|
|
6368
|
+
}
|
|
6354
6369
|
function readRefineJobId2(event) {
|
|
6355
6370
|
const metadata = readRecord3(event.metadataEvent) || event;
|
|
6356
6371
|
const result = readRecord3(metadata.result);
|
|
@@ -6405,7 +6420,9 @@ function getPendingEventsPath(meshId, coordinatorDaemonId) {
|
|
|
6405
6420
|
}
|
|
6406
6421
|
function readPendingMeshCoordinatorEventsFromDisk(meshId, coordinatorDaemonId) {
|
|
6407
6422
|
if (!meshId) return [];
|
|
6408
|
-
const
|
|
6423
|
+
const daemonIds = normalizeCoordinatorDaemonIds(coordinatorDaemonId);
|
|
6424
|
+
const primaryDaemonId = daemonIds[0];
|
|
6425
|
+
const paths = primaryDaemonId ? [getPendingEventsPath(meshId, primaryDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
|
|
6409
6426
|
const events = [];
|
|
6410
6427
|
for (const path39 of paths) {
|
|
6411
6428
|
if (!existsSync12(path39)) continue;
|
|
@@ -6418,7 +6435,7 @@ function readPendingMeshCoordinatorEventsFromDisk(meshId, coordinatorDaemonId) {
|
|
|
6418
6435
|
return [];
|
|
6419
6436
|
}
|
|
6420
6437
|
});
|
|
6421
|
-
const filtered =
|
|
6438
|
+
const filtered = primaryDaemonId && path39 === getPendingEventsPath(meshId) ? parsed.filter((e) => !e.targetCoordinatorDaemonId || daemonIds.includes(e.targetCoordinatorDaemonId)) : parsed;
|
|
6422
6439
|
events.push(...filtered);
|
|
6423
6440
|
} catch {
|
|
6424
6441
|
}
|
|
@@ -6596,6 +6613,8 @@ function selectiveDrainFile(path39, predicate) {
|
|
|
6596
6613
|
}
|
|
6597
6614
|
function drainPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId, opts) {
|
|
6598
6615
|
if (!meshId) return [];
|
|
6616
|
+
const daemonIds = normalizeCoordinatorDaemonIds(coordinatorDaemonId);
|
|
6617
|
+
const primaryDaemonId = daemonIds[0];
|
|
6599
6618
|
const onlyEvents = opts?.onlyEvents;
|
|
6600
6619
|
const matchesFilter = (eventName) => !onlyEvents || onlyEvents.has(eventName);
|
|
6601
6620
|
const merged = [];
|
|
@@ -6611,17 +6630,17 @@ function drainPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId, opts) {
|
|
|
6611
6630
|
try {
|
|
6612
6631
|
const store = MeshRuntimeStore.getInstance();
|
|
6613
6632
|
if (store.pendingEventCount(meshId) > 0) {
|
|
6614
|
-
for (const row of store.drainPendingEvents(meshId,
|
|
6633
|
+
for (const row of store.drainPendingEvents(meshId, daemonIds.length > 0 ? daemonIds : void 0, onlyEvents ? { onlyEvents } : void 0)) {
|
|
6615
6634
|
const event = row.payload;
|
|
6616
6635
|
if (event) pushUnique(event);
|
|
6617
6636
|
}
|
|
6618
6637
|
}
|
|
6619
6638
|
} catch {
|
|
6620
6639
|
}
|
|
6621
|
-
const paths =
|
|
6640
|
+
const paths = primaryDaemonId ? [getPendingEventsPath(meshId, primaryDaemonId), getPendingEventsPath(meshId)] : [getPendingEventsPath(meshId)];
|
|
6622
6641
|
for (const path39 of paths) {
|
|
6623
|
-
const isSharedFile =
|
|
6624
|
-
const targets = (e) => !isSharedFile || !e.targetCoordinatorDaemonId || e.targetCoordinatorDaemonId
|
|
6642
|
+
const isSharedFile = !!primaryDaemonId && path39 === getPendingEventsPath(meshId);
|
|
6643
|
+
const targets = (e) => !isSharedFile || !e.targetCoordinatorDaemonId || daemonIds.includes(e.targetCoordinatorDaemonId);
|
|
6625
6644
|
if (onlyEvents) {
|
|
6626
6645
|
for (const event of selectiveDrainFile(path39, (e) => targets(e) && matchesFilter(e.event))) {
|
|
6627
6646
|
pushUnique(event);
|
|
@@ -6645,6 +6664,7 @@ function drainPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId, opts) {
|
|
|
6645
6664
|
}
|
|
6646
6665
|
function getPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
|
|
6647
6666
|
if (!meshId) return [];
|
|
6667
|
+
const daemonIds = normalizeCoordinatorDaemonIds(coordinatorDaemonId);
|
|
6648
6668
|
const merged = [];
|
|
6649
6669
|
const seenFingerprints = /* @__PURE__ */ new Set();
|
|
6650
6670
|
const pushUnique = (event) => {
|
|
@@ -6658,14 +6678,14 @@ function getPendingMeshCoordinatorEvents(meshId, coordinatorDaemonId) {
|
|
|
6658
6678
|
try {
|
|
6659
6679
|
const store = MeshRuntimeStore.getInstance();
|
|
6660
6680
|
if (store.pendingEventCount(meshId) > 0) {
|
|
6661
|
-
for (const row of store.peekPendingEvents(meshId,
|
|
6681
|
+
for (const row of store.peekPendingEvents(meshId, daemonIds.length > 0 ? daemonIds : void 0)) {
|
|
6662
6682
|
const event = row.payload;
|
|
6663
6683
|
if (event) pushUnique(event);
|
|
6664
6684
|
}
|
|
6665
6685
|
}
|
|
6666
6686
|
} catch {
|
|
6667
6687
|
}
|
|
6668
|
-
for (const event of readPendingMeshCoordinatorEventsFromDisk(meshId,
|
|
6688
|
+
for (const event of readPendingMeshCoordinatorEventsFromDisk(meshId, daemonIds)) {
|
|
6669
6689
|
pushUnique(event);
|
|
6670
6690
|
}
|
|
6671
6691
|
return reconcilePendingMeshCoordinatorEvents(meshId, merged);
|
|
@@ -7364,6 +7384,14 @@ var init_mesh_routing = __esm({
|
|
|
7364
7384
|
|
|
7365
7385
|
// src/mesh/mesh-events-coordinator.ts
|
|
7366
7386
|
import { existsSync as existsSync14 } from "fs";
|
|
7387
|
+
function resolveCoordinatorDrainDaemonIds(components) {
|
|
7388
|
+
const ids = /* @__PURE__ */ new Set();
|
|
7389
|
+
const statusInstanceId = readNonEmptyString2(components.statusInstanceId);
|
|
7390
|
+
if (statusInstanceId) ids.add(statusInstanceId);
|
|
7391
|
+
const machineId = readNonEmptyString2(loadConfig().machineId);
|
|
7392
|
+
if (machineId) ids.add(machineId);
|
|
7393
|
+
return [...ids];
|
|
7394
|
+
}
|
|
7367
7395
|
function getCachedMeshByWorkspace(workspace) {
|
|
7368
7396
|
const now = Date.now();
|
|
7369
7397
|
const cached2 = meshByWorkspaceCache.get(workspace);
|
|
@@ -8488,8 +8516,8 @@ function setupMeshEventForwarding(components) {
|
|
|
8488
8516
|
const status = readNonEmptyString2(flushState.status).toLowerCase();
|
|
8489
8517
|
if (status === "idle") {
|
|
8490
8518
|
try {
|
|
8491
|
-
const
|
|
8492
|
-
const pendingEvents = drainPendingMeshCoordinatorEvents(coordinatorMeshId,
|
|
8519
|
+
const drainDaemonIds = resolveCoordinatorDrainDaemonIds(components);
|
|
8520
|
+
const pendingEvents = drainPendingMeshCoordinatorEvents(coordinatorMeshId, drainDaemonIds.length > 0 ? drainDaemonIds : void 0);
|
|
8493
8521
|
if (pendingEvents.length > 0) {
|
|
8494
8522
|
LOG.info("MeshEvents", `Auto-flushing ${pendingEvents.length} pending coordinator event(s) for mesh ${coordinatorMeshId} on coordinator idle`);
|
|
8495
8523
|
for (const pending of pendingEvents) {
|
|
@@ -8604,6 +8632,14 @@ function resolveReconcileIntervalMs() {
|
|
|
8604
8632
|
}
|
|
8605
8633
|
return DEFAULT_RECONCILE_INTERVAL_MS;
|
|
8606
8634
|
}
|
|
8635
|
+
function resolveCoordinatorDaemonIds(components) {
|
|
8636
|
+
const ids = /* @__PURE__ */ new Set();
|
|
8637
|
+
const statusInstanceId = readNonEmptyString2(components.statusInstanceId);
|
|
8638
|
+
if (statusInstanceId) ids.add(statusInstanceId);
|
|
8639
|
+
const machineId = readNonEmptyString2(loadConfig().machineId);
|
|
8640
|
+
if (machineId) ids.add(machineId);
|
|
8641
|
+
return [...ids];
|
|
8642
|
+
}
|
|
8607
8643
|
function findLiveCoordinators(components) {
|
|
8608
8644
|
const out = [];
|
|
8609
8645
|
for (const inst of components.instanceManager.getByCategory("cli")) {
|
|
@@ -8636,6 +8672,7 @@ async function runMeshReconcileTick(components) {
|
|
|
8636
8672
|
else byMesh.set(c.meshId, [c]);
|
|
8637
8673
|
}
|
|
8638
8674
|
const localDaemonId = readNonEmptyString2(loadConfig().machineId) || void 0;
|
|
8675
|
+
const drainDaemonIds = resolveCoordinatorDaemonIds(components);
|
|
8639
8676
|
const dispatchMeshCommand = components.dispatchMeshCommand;
|
|
8640
8677
|
const store = (() => {
|
|
8641
8678
|
try {
|
|
@@ -8666,7 +8703,7 @@ async function runMeshReconcileTick(components) {
|
|
|
8666
8703
|
try {
|
|
8667
8704
|
pendingEvents = drainPendingMeshCoordinatorEvents(
|
|
8668
8705
|
meshId,
|
|
8669
|
-
localDaemonId,
|
|
8706
|
+
drainDaemonIds.length > 0 ? drainDaemonIds : localDaemonId,
|
|
8670
8707
|
forceOnly ? { onlyEvents: MESH_FORCE_INJECT_EVENTS } : void 0
|
|
8671
8708
|
);
|
|
8672
8709
|
} catch (e) {
|
|
@@ -55453,7 +55490,8 @@ async function initDaemonComponents(config) {
|
|
|
55453
55490
|
detectedIdes: detectedIdesRef,
|
|
55454
55491
|
refreshProviderAvailability,
|
|
55455
55492
|
dispatchMeshCommand: config.dispatchMeshCommand,
|
|
55456
|
-
onMeshCoordinatorEventForwarded: config.onMeshCoordinatorEventForwarded
|
|
55493
|
+
onMeshCoordinatorEventForwarded: config.onMeshCoordinatorEventForwarded,
|
|
55494
|
+
statusInstanceId: config.statusInstanceId
|
|
55457
55495
|
};
|
|
55458
55496
|
setupMeshEventForwarding(components);
|
|
55459
55497
|
components.meshReconcileLoop = setupMeshReconcileLoop(components);
|