adhdev 0.9.82-rc.23 → 0.9.82-rc.25
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/cli/index.js +389 -204
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +389 -204
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/vendor/mcp-server/index.js +5 -5
- package/vendor/mcp-server/index.js.map +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -3810,6 +3810,36 @@ function getQueuePath(meshId) {
|
|
|
3810
3810
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
3811
3811
|
return (0, import_path4.join)(getLedgerDir(), `${safe}.queue.json`);
|
|
3812
3812
|
}
|
|
3813
|
+
function getLockPath(meshId) {
|
|
3814
|
+
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
3815
|
+
return (0, import_path4.join)(getLedgerDir(), `${safe}.queue.lock`);
|
|
3816
|
+
}
|
|
3817
|
+
function withQueueLock(meshId, fn) {
|
|
3818
|
+
const lockPath = getLockPath(meshId);
|
|
3819
|
+
let fd = -1;
|
|
3820
|
+
for (let i = 0; i < 10; i++) {
|
|
3821
|
+
try {
|
|
3822
|
+
fd = (0, import_fs4.openSync)(lockPath, "wx");
|
|
3823
|
+
break;
|
|
3824
|
+
} catch {
|
|
3825
|
+
const deadline = Date.now() + 30;
|
|
3826
|
+
while (Date.now() < deadline) {
|
|
3827
|
+
}
|
|
3828
|
+
}
|
|
3829
|
+
}
|
|
3830
|
+
try {
|
|
3831
|
+
return fn();
|
|
3832
|
+
} finally {
|
|
3833
|
+
if (fd !== -1) try {
|
|
3834
|
+
(0, import_fs4.closeSync)(fd);
|
|
3835
|
+
} catch {
|
|
3836
|
+
}
|
|
3837
|
+
try {
|
|
3838
|
+
(0, import_fs4.unlinkSync)(lockPath);
|
|
3839
|
+
} catch {
|
|
3840
|
+
}
|
|
3841
|
+
}
|
|
3842
|
+
}
|
|
3813
3843
|
function readQueue(meshId) {
|
|
3814
3844
|
const path42 = getQueuePath(meshId);
|
|
3815
3845
|
if (!(0, import_fs4.existsSync)(path42)) return [];
|
|
@@ -3825,20 +3855,22 @@ function writeQueue(meshId, queue) {
|
|
|
3825
3855
|
(0, import_fs4.writeFileSync)(path42, JSON.stringify(queue, null, 2), "utf-8");
|
|
3826
3856
|
}
|
|
3827
3857
|
function enqueueTask(meshId, message, opts) {
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3841
|
-
|
|
3858
|
+
return withQueueLock(meshId, () => {
|
|
3859
|
+
const queue = readQueue(meshId);
|
|
3860
|
+
const entry = {
|
|
3861
|
+
id: (0, import_crypto5.randomUUID)(),
|
|
3862
|
+
meshId,
|
|
3863
|
+
message,
|
|
3864
|
+
status: "pending",
|
|
3865
|
+
targetNodeId: opts?.targetNodeId,
|
|
3866
|
+
targetSessionId: opts?.targetSessionId,
|
|
3867
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3868
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3869
|
+
};
|
|
3870
|
+
queue.push(entry);
|
|
3871
|
+
writeQueue(meshId, queue);
|
|
3872
|
+
return entry;
|
|
3873
|
+
});
|
|
3842
3874
|
}
|
|
3843
3875
|
function getQueue(meshId, opts) {
|
|
3844
3876
|
let queue = readQueue(meshId);
|
|
@@ -3849,100 +3881,111 @@ function getQueue(meshId, opts) {
|
|
|
3849
3881
|
return queue;
|
|
3850
3882
|
}
|
|
3851
3883
|
function claimNextTask(meshId, nodeId, sessionId) {
|
|
3852
|
-
|
|
3853
|
-
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3867
|
-
|
|
3868
|
-
|
|
3869
|
-
|
|
3870
|
-
|
|
3884
|
+
return withQueueLock(meshId, () => {
|
|
3885
|
+
const queue = readQueue(meshId);
|
|
3886
|
+
const hasActiveAssignment = queue.some((q) => q.status === "assigned" && (q.assignedSessionId === sessionId || q.assignedNodeId === nodeId));
|
|
3887
|
+
if (hasActiveAssignment) return null;
|
|
3888
|
+
let targetIdx = queue.findIndex((q) => q.status === "pending" && q.targetSessionId === sessionId);
|
|
3889
|
+
if (targetIdx === -1) {
|
|
3890
|
+
targetIdx = queue.findIndex((q) => q.status === "pending" && q.targetNodeId === nodeId && !q.targetSessionId);
|
|
3891
|
+
}
|
|
3892
|
+
if (targetIdx === -1) {
|
|
3893
|
+
targetIdx = queue.findIndex((q) => q.status === "pending" && !q.targetNodeId && !q.targetSessionId);
|
|
3894
|
+
}
|
|
3895
|
+
if (targetIdx === -1) return null;
|
|
3896
|
+
const entry = queue[targetIdx];
|
|
3897
|
+
entry.status = "assigned";
|
|
3898
|
+
entry.assignedNodeId = nodeId;
|
|
3899
|
+
entry.assignedSessionId = sessionId;
|
|
3900
|
+
entry.dispatchTimestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
3901
|
+
entry.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3902
|
+
writeQueue(meshId, queue);
|
|
3903
|
+
return entry;
|
|
3904
|
+
});
|
|
3871
3905
|
}
|
|
3872
3906
|
function updateTaskStatus(meshId, taskId, status) {
|
|
3873
|
-
|
|
3874
|
-
|
|
3875
|
-
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3907
|
+
return withQueueLock(meshId, () => {
|
|
3908
|
+
const queue = readQueue(meshId);
|
|
3909
|
+
const idx = queue.findIndex((q) => q.id === taskId);
|
|
3910
|
+
if (idx === -1) return null;
|
|
3911
|
+
queue[idx].status = status;
|
|
3912
|
+
queue[idx].updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3913
|
+
writeQueue(meshId, queue);
|
|
3914
|
+
return queue[idx];
|
|
3915
|
+
});
|
|
3880
3916
|
}
|
|
3881
3917
|
function recordTaskAutoLaunch(meshId, taskId, autoLaunch) {
|
|
3882
|
-
|
|
3883
|
-
|
|
3884
|
-
|
|
3885
|
-
|
|
3886
|
-
|
|
3887
|
-
...autoLaunch,
|
|
3888
|
-
updatedAt
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
return queue[idx];
|
|
3918
|
+
return withQueueLock(meshId, () => {
|
|
3919
|
+
const queue = readQueue(meshId);
|
|
3920
|
+
const idx = queue.findIndex((q) => q.id === taskId);
|
|
3921
|
+
if (idx === -1) return null;
|
|
3922
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3923
|
+
queue[idx].autoLaunch = { ...autoLaunch, updatedAt: now };
|
|
3924
|
+
queue[idx].updatedAt = now;
|
|
3925
|
+
writeQueue(meshId, queue);
|
|
3926
|
+
return queue[idx];
|
|
3927
|
+
});
|
|
3893
3928
|
}
|
|
3894
3929
|
function cancelTask(meshId, taskId, opts) {
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3930
|
+
return withQueueLock(meshId, () => {
|
|
3931
|
+
const queue = readQueue(meshId);
|
|
3932
|
+
const idx = queue.findIndex((q) => q.id === taskId);
|
|
3933
|
+
if (idx === -1) return null;
|
|
3934
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3935
|
+
queue[idx].status = "cancelled";
|
|
3936
|
+
queue[idx].updatedAt = now;
|
|
3937
|
+
queue[idx].cancelledAt = now;
|
|
3938
|
+
if (opts?.reason) queue[idx].cancelReason = opts.reason;
|
|
3939
|
+
writeQueue(meshId, queue);
|
|
3940
|
+
return queue[idx];
|
|
3941
|
+
});
|
|
3905
3942
|
}
|
|
3906
3943
|
function requeueTask(meshId, taskId, opts) {
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
3914
|
-
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3944
|
+
return withQueueLock(meshId, () => {
|
|
3945
|
+
const queue = readQueue(meshId);
|
|
3946
|
+
const idx = queue.findIndex((q) => q.id === taskId);
|
|
3947
|
+
if (idx === -1) return null;
|
|
3948
|
+
const entry = queue[idx];
|
|
3949
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3950
|
+
entry.status = "pending";
|
|
3951
|
+
delete entry.assignedNodeId;
|
|
3952
|
+
delete entry.assignedSessionId;
|
|
3953
|
+
delete entry.cancelledAt;
|
|
3954
|
+
delete entry.cancelReason;
|
|
3955
|
+
if (opts?.clearTargetNode) delete entry.targetNodeId;
|
|
3956
|
+
if (typeof opts?.targetNodeId === "string") entry.targetNodeId = opts.targetNodeId;
|
|
3957
|
+
if (opts?.clearTargetSession !== false) delete entry.targetSessionId;
|
|
3958
|
+
if (typeof opts?.targetSessionId === "string") entry.targetSessionId = opts.targetSessionId;
|
|
3959
|
+
entry.updatedAt = now;
|
|
3960
|
+
entry.requeuedAt = now;
|
|
3961
|
+
entry.requeueCount = (entry.requeueCount || 0) + 1;
|
|
3962
|
+
if (opts?.reason) entry.requeueReason = opts.reason;
|
|
3963
|
+
writeQueue(meshId, queue);
|
|
3964
|
+
return entry;
|
|
3965
|
+
});
|
|
3966
|
+
}
|
|
3967
|
+
function updateSessionTaskStatus(meshId, sessionId, status, opts) {
|
|
3968
|
+
return withQueueLock(meshId, () => {
|
|
3969
|
+
const queue = readQueue(meshId);
|
|
3970
|
+
const occurredAtTime = opts?.occurredAt ? new Date(opts.occurredAt).getTime() : Number.NaN;
|
|
3971
|
+
const hasOccurredAt = Number.isFinite(occurredAtTime);
|
|
3972
|
+
let bestIdx = -1;
|
|
3973
|
+
let bestTime = 0;
|
|
3974
|
+
for (let i = queue.length - 1; i >= 0; i--) {
|
|
3975
|
+
if (queue[i].assignedSessionId !== sessionId || queue[i].status !== "assigned") continue;
|
|
3934
3976
|
const time3 = new Date(queue[i].dispatchTimestamp || queue[i].updatedAt).getTime();
|
|
3977
|
+
if (hasOccurredAt && Number.isFinite(time3) && time3 > occurredAtTime) continue;
|
|
3935
3978
|
if (time3 > bestTime) {
|
|
3936
3979
|
bestTime = time3;
|
|
3937
3980
|
bestIdx = i;
|
|
3938
3981
|
}
|
|
3939
3982
|
}
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3983
|
+
if (bestIdx === -1) return null;
|
|
3984
|
+
queue[bestIdx].status = status;
|
|
3985
|
+
queue[bestIdx].updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3986
|
+
writeQueue(meshId, queue);
|
|
3987
|
+
return queue[bestIdx];
|
|
3988
|
+
});
|
|
3946
3989
|
}
|
|
3947
3990
|
function getMeshQueueStats(meshId) {
|
|
3948
3991
|
const queue = readQueue(meshId);
|
|
@@ -4351,21 +4394,70 @@ __export(mesh_events_exports, {
|
|
|
4351
4394
|
triggerMeshQueue: () => triggerMeshQueue,
|
|
4352
4395
|
tryAssignQueueTask: () => tryAssignQueueTask
|
|
4353
4396
|
});
|
|
4397
|
+
function sweepExpiredRemoteIdleSessions() {
|
|
4398
|
+
const now = Date.now();
|
|
4399
|
+
for (const [key, session] of remoteIdleSessions) {
|
|
4400
|
+
if (session.expiresAt <= now) remoteIdleSessions.delete(key);
|
|
4401
|
+
}
|
|
4402
|
+
}
|
|
4403
|
+
function getPendingEventsPath(meshId) {
|
|
4404
|
+
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
4405
|
+
return (0, import_path5.join)(getLedgerDir(), `${safe}.pending-events.jsonl`);
|
|
4406
|
+
}
|
|
4354
4407
|
function queuePendingMeshCoordinatorEvent(event) {
|
|
4355
|
-
|
|
4408
|
+
try {
|
|
4409
|
+
(0, import_fs6.appendFileSync)(getPendingEventsPath(event.meshId), JSON.stringify(event) + "\n", "utf-8");
|
|
4410
|
+
return true;
|
|
4411
|
+
} catch (e) {
|
|
4412
|
+
LOG.warn("MeshEvents", `Failed to persist pending coordinator event: ${e?.message || e}`);
|
|
4356
4413
|
return false;
|
|
4357
4414
|
}
|
|
4358
|
-
pendingMeshCoordinatorEvents.push(event);
|
|
4359
|
-
return true;
|
|
4360
4415
|
}
|
|
4361
|
-
function drainPendingMeshCoordinatorEvents() {
|
|
4362
|
-
|
|
4416
|
+
function drainPendingMeshCoordinatorEvents(meshId) {
|
|
4417
|
+
if (!meshId) return [];
|
|
4418
|
+
const path42 = getPendingEventsPath(meshId);
|
|
4419
|
+
if (!(0, import_fs6.existsSync)(path42)) return [];
|
|
4420
|
+
try {
|
|
4421
|
+
const raw = (0, import_fs6.readFileSync)(path42, "utf-8");
|
|
4422
|
+
try {
|
|
4423
|
+
(0, import_fs6.unlinkSync)(path42);
|
|
4424
|
+
} catch {
|
|
4425
|
+
}
|
|
4426
|
+
return raw.split("\n").filter(Boolean).flatMap((line) => {
|
|
4427
|
+
try {
|
|
4428
|
+
return [JSON.parse(line)];
|
|
4429
|
+
} catch {
|
|
4430
|
+
return [];
|
|
4431
|
+
}
|
|
4432
|
+
});
|
|
4433
|
+
} catch {
|
|
4434
|
+
return [];
|
|
4435
|
+
}
|
|
4363
4436
|
}
|
|
4364
|
-
function getPendingMeshCoordinatorEvents() {
|
|
4365
|
-
|
|
4437
|
+
function getPendingMeshCoordinatorEvents(meshId) {
|
|
4438
|
+
if (!meshId) return [];
|
|
4439
|
+
const path42 = getPendingEventsPath(meshId);
|
|
4440
|
+
if (!(0, import_fs6.existsSync)(path42)) return [];
|
|
4441
|
+
try {
|
|
4442
|
+
const raw = (0, import_fs6.readFileSync)(path42, "utf-8");
|
|
4443
|
+
return raw.split("\n").filter(Boolean).flatMap((line) => {
|
|
4444
|
+
try {
|
|
4445
|
+
return [JSON.parse(line)];
|
|
4446
|
+
} catch {
|
|
4447
|
+
return [];
|
|
4448
|
+
}
|
|
4449
|
+
});
|
|
4450
|
+
} catch {
|
|
4451
|
+
return [];
|
|
4452
|
+
}
|
|
4366
4453
|
}
|
|
4367
|
-
function clearPendingMeshCoordinatorEvents() {
|
|
4368
|
-
|
|
4454
|
+
function clearPendingMeshCoordinatorEvents(meshId) {
|
|
4455
|
+
if (!meshId) return;
|
|
4456
|
+
const path42 = getPendingEventsPath(meshId);
|
|
4457
|
+
if ((0, import_fs6.existsSync)(path42)) try {
|
|
4458
|
+
(0, import_fs6.unlinkSync)(path42);
|
|
4459
|
+
} catch {
|
|
4460
|
+
}
|
|
4369
4461
|
}
|
|
4370
4462
|
function readNonEmptyString(value) {
|
|
4371
4463
|
return typeof value === "string" && value.trim() ? value.trim() : "";
|
|
@@ -4411,6 +4503,38 @@ function shouldSuppressIntentionalCleanupStop(args) {
|
|
|
4411
4503
|
if (isIntentionalCleanupStopMetadata(args.metadataEvent)) return true;
|
|
4412
4504
|
return hasRecentIntentionalCleanupStop(args.meshId, args.sessionId, args.nodeId);
|
|
4413
4505
|
}
|
|
4506
|
+
function readEventTimestamp(value) {
|
|
4507
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
4508
|
+
if (typeof value === "string" && value.trim()) {
|
|
4509
|
+
const numeric = Number(value);
|
|
4510
|
+
if (Number.isFinite(numeric)) return numeric;
|
|
4511
|
+
const parsed = Date.parse(value);
|
|
4512
|
+
if (Number.isFinite(parsed)) return parsed;
|
|
4513
|
+
}
|
|
4514
|
+
return null;
|
|
4515
|
+
}
|
|
4516
|
+
function buildMeshCompletionFingerprint(args) {
|
|
4517
|
+
const timestampPart = Number.isFinite(args.timestamp) ? String(args.timestamp) : readNonEmptyString(args.finalSummary).slice(0, 200);
|
|
4518
|
+
return [
|
|
4519
|
+
args.meshId,
|
|
4520
|
+
args.event,
|
|
4521
|
+
args.sessionId,
|
|
4522
|
+
args.providerType || "",
|
|
4523
|
+
args.providerSessionId || "",
|
|
4524
|
+
timestampPart
|
|
4525
|
+
].join("::");
|
|
4526
|
+
}
|
|
4527
|
+
function isDuplicateMeshCompletionEvent(args) {
|
|
4528
|
+
const fingerprint = buildMeshCompletionFingerprint(args);
|
|
4529
|
+
if (!fingerprint) return false;
|
|
4530
|
+
const now = Date.now();
|
|
4531
|
+
for (const [key, seenAt] of recentCompletionFingerprints.entries()) {
|
|
4532
|
+
if (now - seenAt > RECENT_COMPLETION_FINGERPRINT_TTL_MS) recentCompletionFingerprints.delete(key);
|
|
4533
|
+
}
|
|
4534
|
+
if (recentCompletionFingerprints.has(fingerprint)) return true;
|
|
4535
|
+
recentCompletionFingerprints.set(fingerprint, now);
|
|
4536
|
+
return false;
|
|
4537
|
+
}
|
|
4414
4538
|
function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType) {
|
|
4415
4539
|
const task = claimNextTask(meshId, nodeId, sessionId);
|
|
4416
4540
|
if (!task) {
|
|
@@ -4429,7 +4553,16 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
|
|
|
4429
4553
|
message: task.message
|
|
4430
4554
|
}).catch((e) => {
|
|
4431
4555
|
LOG.error("MeshQueue", `Failed to dispatch task via P2P to remote node ${nodeId}: ${e?.message}`);
|
|
4432
|
-
updateTaskStatus(meshId, task.id, "
|
|
4556
|
+
updateTaskStatus(meshId, task.id, "pending");
|
|
4557
|
+
try {
|
|
4558
|
+
appendLedgerEntry(meshId, {
|
|
4559
|
+
kind: "dispatch_failed",
|
|
4560
|
+
nodeId,
|
|
4561
|
+
sessionId,
|
|
4562
|
+
payload: { taskId: task.id, error: e?.message, retryable: true }
|
|
4563
|
+
});
|
|
4564
|
+
} catch {
|
|
4565
|
+
}
|
|
4433
4566
|
});
|
|
4434
4567
|
return true;
|
|
4435
4568
|
}
|
|
@@ -4763,18 +4896,36 @@ function injectMeshSystemMessage(components, args) {
|
|
|
4763
4896
|
LOG.info("MeshEvents", `Suppressed ${args.event} for intentionally cleanup-stopped session ${eventSessionId || "(unknown session)"}`);
|
|
4764
4897
|
return { success: true, forwarded: 0, suppressed: true, intentionalCleanupStop: true };
|
|
4765
4898
|
}
|
|
4899
|
+
const eventTimestamp = readEventTimestamp(args.metadataEvent.timestamp);
|
|
4900
|
+
if (args.event === "agent:generating_completed" && eventSessionId) {
|
|
4901
|
+
const duplicateCompletion = isDuplicateMeshCompletionEvent({
|
|
4902
|
+
meshId: args.meshId,
|
|
4903
|
+
event: args.event,
|
|
4904
|
+
sessionId: eventSessionId,
|
|
4905
|
+
providerType: readNonEmptyString(args.metadataEvent.providerType) || void 0,
|
|
4906
|
+
providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0,
|
|
4907
|
+
timestamp: eventTimestamp,
|
|
4908
|
+
finalSummary: readNonEmptyString(args.metadataEvent.finalSummary) || void 0
|
|
4909
|
+
});
|
|
4910
|
+
if (duplicateCompletion) {
|
|
4911
|
+
LOG.info("MeshEvents", `Suppressed duplicate completion for mesh ${args.meshId} session ${eventSessionId}`);
|
|
4912
|
+
return { success: true, forwarded: 0, suppressed: true, duplicateCompletion: true };
|
|
4913
|
+
}
|
|
4914
|
+
}
|
|
4766
4915
|
let completedTaskForLedger = null;
|
|
4767
4916
|
if (args.event === "agent:generating_completed") {
|
|
4768
4917
|
const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
|
|
4769
4918
|
const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
|
|
4770
4919
|
const providerType = readNonEmptyString(args.metadataEvent.providerType);
|
|
4771
4920
|
if (sessionId) {
|
|
4772
|
-
const completedTask = updateSessionTaskStatus(args.meshId, sessionId, "completed"
|
|
4921
|
+
const completedTask = updateSessionTaskStatus(args.meshId, sessionId, "completed", {
|
|
4922
|
+
occurredAt: eventTimestamp !== null ? new Date(eventTimestamp).toISOString() : void 0
|
|
4923
|
+
});
|
|
4773
4924
|
completedTaskForLedger = completedTask ? { id: completedTask.id } : null;
|
|
4774
4925
|
if (nodeId && providerType) {
|
|
4775
|
-
|
|
4926
|
+
setImmediate(() => {
|
|
4776
4927
|
tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
|
|
4777
|
-
}
|
|
4928
|
+
});
|
|
4778
4929
|
}
|
|
4779
4930
|
}
|
|
4780
4931
|
} else if (args.event === "agent:ready") {
|
|
@@ -4812,13 +4963,17 @@ function injectMeshSystemMessage(components, args) {
|
|
|
4812
4963
|
}
|
|
4813
4964
|
}
|
|
4814
4965
|
if (sessionId && nodeId && providerType) {
|
|
4815
|
-
|
|
4816
|
-
|
|
4966
|
+
sweepExpiredRemoteIdleSessions();
|
|
4967
|
+
remoteIdleSessions.set(`${nodeId}:${sessionId}`, {
|
|
4968
|
+
nodeId,
|
|
4969
|
+
sessionId,
|
|
4970
|
+
providerType,
|
|
4971
|
+
expiresAt: Date.now() + REMOTE_IDLE_SESSION_TTL_MS
|
|
4972
|
+
});
|
|
4973
|
+
setImmediate(() => {
|
|
4817
4974
|
const assigned = tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
|
|
4818
|
-
if (assigned) {
|
|
4819
|
-
|
|
4820
|
-
}
|
|
4821
|
-
}, 500);
|
|
4975
|
+
if (assigned) remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
|
|
4976
|
+
});
|
|
4822
4977
|
}
|
|
4823
4978
|
} else if (args.event === "agent:generating_started") {
|
|
4824
4979
|
const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
|
|
@@ -4979,6 +5134,7 @@ function handleMeshForwardEvent(components, payload) {
|
|
|
4979
5134
|
providerType: readNonEmptyString(payload.providerType),
|
|
4980
5135
|
providerSessionId: readNonEmptyString(payload.providerSessionId),
|
|
4981
5136
|
finalSummary: readNonEmptyString(payload.finalSummary) || readNonEmptyString(payload.summary),
|
|
5137
|
+
...payload.timestamp !== void 0 ? { timestamp: payload.timestamp } : {},
|
|
4982
5138
|
intentional: payload.intentional === true,
|
|
4983
5139
|
intentionalStop: payload.intentionalStop === true,
|
|
4984
5140
|
operatorCleanup: payload.operatorCleanup === true,
|
|
@@ -5021,19 +5177,20 @@ function setupMeshEventForwarding(components) {
|
|
|
5021
5177
|
});
|
|
5022
5178
|
});
|
|
5023
5179
|
}
|
|
5024
|
-
var
|
|
5180
|
+
var import_fs6, import_path5, REMOTE_IDLE_SESSION_TTL_MS, remoteIdleSessions, MESH_COORDINATOR_EVENTS, EVENT_TO_LEDGER_KIND, INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS, RECENT_COMPLETION_FINGERPRINT_TTL_MS, recentCompletionFingerprints, autoLaunchInProgress, autoLaunchCooldownUntil, AUTO_LAUNCH_COOLDOWN_MS;
|
|
5025
5181
|
var init_mesh_events = __esm({
|
|
5026
5182
|
"../../oss/packages/daemon-core/src/mesh/mesh-events.ts"() {
|
|
5027
5183
|
"use strict";
|
|
5184
|
+
import_fs6 = require("fs");
|
|
5185
|
+
import_path5 = require("path");
|
|
5028
5186
|
init_config();
|
|
5029
5187
|
init_mesh_config();
|
|
5030
5188
|
init_cli_detector();
|
|
5031
5189
|
init_logger();
|
|
5032
5190
|
init_mesh_ledger();
|
|
5033
5191
|
init_mesh_work_queue();
|
|
5192
|
+
REMOTE_IDLE_SESSION_TTL_MS = 5 * 60 * 1e3;
|
|
5034
5193
|
remoteIdleSessions = /* @__PURE__ */ new Map();
|
|
5035
|
-
MAX_PENDING_EVENTS = 50;
|
|
5036
|
-
pendingMeshCoordinatorEvents = [];
|
|
5037
5194
|
MESH_COORDINATOR_EVENTS = /* @__PURE__ */ new Set([
|
|
5038
5195
|
"agent:generating_started",
|
|
5039
5196
|
"agent:generating_completed",
|
|
@@ -5049,6 +5206,8 @@ var init_mesh_events = __esm({
|
|
|
5049
5206
|
"monitor:long_generating": "task_stalled"
|
|
5050
5207
|
};
|
|
5051
5208
|
INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS = 30 * 60 * 1e3;
|
|
5209
|
+
RECENT_COMPLETION_FINGERPRINT_TTL_MS = 10 * 60 * 1e3;
|
|
5210
|
+
recentCompletionFingerprints = /* @__PURE__ */ new Map();
|
|
5052
5211
|
autoLaunchInProgress = /* @__PURE__ */ new Set();
|
|
5053
5212
|
autoLaunchCooldownUntil = /* @__PURE__ */ new Map();
|
|
5054
5213
|
AUTO_LAUNCH_COOLDOWN_MS = 5e3;
|
|
@@ -5176,7 +5335,7 @@ function isPlainObject2(value) {
|
|
|
5176
5335
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
5177
5336
|
}
|
|
5178
5337
|
function getStatePath() {
|
|
5179
|
-
return (0,
|
|
5338
|
+
return (0, import_path6.join)(getConfigDir(), "state.json");
|
|
5180
5339
|
}
|
|
5181
5340
|
function normalizeState(raw) {
|
|
5182
5341
|
const parsed = isPlainObject2(raw) ? raw : {};
|
|
@@ -5212,11 +5371,11 @@ function normalizeState(raw) {
|
|
|
5212
5371
|
}
|
|
5213
5372
|
function loadState() {
|
|
5214
5373
|
const statePath = getStatePath();
|
|
5215
|
-
if (!(0,
|
|
5374
|
+
if (!(0, import_fs7.existsSync)(statePath)) {
|
|
5216
5375
|
return { ...DEFAULT_STATE };
|
|
5217
5376
|
}
|
|
5218
5377
|
try {
|
|
5219
|
-
const raw = (0,
|
|
5378
|
+
const raw = (0, import_fs7.readFileSync)(statePath, "utf-8");
|
|
5220
5379
|
return normalizeState(JSON.parse(raw));
|
|
5221
5380
|
} catch {
|
|
5222
5381
|
return { ...DEFAULT_STATE };
|
|
@@ -5225,17 +5384,17 @@ function loadState() {
|
|
|
5225
5384
|
function saveState(state) {
|
|
5226
5385
|
const statePath = getStatePath();
|
|
5227
5386
|
const normalized = normalizeState(state);
|
|
5228
|
-
(0,
|
|
5387
|
+
(0, import_fs7.writeFileSync)(statePath, JSON.stringify(normalized, null, 2), { encoding: "utf-8", mode: 384 });
|
|
5229
5388
|
}
|
|
5230
5389
|
function resetState() {
|
|
5231
5390
|
saveState({ ...DEFAULT_STATE });
|
|
5232
5391
|
}
|
|
5233
|
-
var
|
|
5392
|
+
var import_fs7, import_path6, DEFAULT_STATE;
|
|
5234
5393
|
var init_state_store = __esm({
|
|
5235
5394
|
"../../oss/packages/daemon-core/src/config/state-store.ts"() {
|
|
5236
5395
|
"use strict";
|
|
5237
|
-
|
|
5238
|
-
|
|
5396
|
+
import_fs7 = require("fs");
|
|
5397
|
+
import_path6 = require("path");
|
|
5239
5398
|
init_config();
|
|
5240
5399
|
DEFAULT_STATE = {
|
|
5241
5400
|
recentActivity: [],
|
|
@@ -5268,7 +5427,7 @@ function findCliCommand(command) {
|
|
|
5268
5427
|
if (path10.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~")) {
|
|
5269
5428
|
const candidate = trimmed.startsWith("~") ? path10.join((0, import_os2.homedir)(), trimmed.slice(1)) : trimmed;
|
|
5270
5429
|
const resolved = path10.isAbsolute(candidate) ? candidate : path10.resolve(candidate);
|
|
5271
|
-
return (0,
|
|
5430
|
+
return (0, import_fs8.existsSync)(resolved) ? resolved : null;
|
|
5272
5431
|
}
|
|
5273
5432
|
try {
|
|
5274
5433
|
const result = (0, import_child_process2.execSync)(
|
|
@@ -5299,9 +5458,9 @@ function checkPathExists(paths) {
|
|
|
5299
5458
|
if (normalized.includes("*")) {
|
|
5300
5459
|
const username = home.split(/[\\/]/).pop() || "";
|
|
5301
5460
|
const resolved = normalized.replace("*", username);
|
|
5302
|
-
if ((0,
|
|
5461
|
+
if ((0, import_fs8.existsSync)(resolved)) return resolved;
|
|
5303
5462
|
} else {
|
|
5304
|
-
if ((0,
|
|
5463
|
+
if ((0, import_fs8.existsSync)(normalized)) return normalized;
|
|
5305
5464
|
}
|
|
5306
5465
|
}
|
|
5307
5466
|
return null;
|
|
@@ -5315,7 +5474,7 @@ async function detectIDEs(providerLoader) {
|
|
|
5315
5474
|
let resolvedCli = cliPath;
|
|
5316
5475
|
if (!resolvedCli && appPath && os32 === "darwin") {
|
|
5317
5476
|
const bundledCli = `${appPath}/Contents/Resources/app/bin/${def.cli}`;
|
|
5318
|
-
if ((0,
|
|
5477
|
+
if ((0, import_fs8.existsSync)(bundledCli)) resolvedCli = bundledCli;
|
|
5319
5478
|
}
|
|
5320
5479
|
if (!resolvedCli && appPath && os32 === "win32") {
|
|
5321
5480
|
const { dirname: dirname13 } = await import("path");
|
|
@@ -5328,7 +5487,7 @@ async function detectIDEs(providerLoader) {
|
|
|
5328
5487
|
`${appDir}\\\\resources\\\\app\\\\bin\\\\${def.cli}.cmd`
|
|
5329
5488
|
];
|
|
5330
5489
|
for (const c of candidates) {
|
|
5331
|
-
if ((0,
|
|
5490
|
+
if ((0, import_fs8.existsSync)(c)) {
|
|
5332
5491
|
resolvedCli = c;
|
|
5333
5492
|
break;
|
|
5334
5493
|
}
|
|
@@ -5349,12 +5508,12 @@ async function detectIDEs(providerLoader) {
|
|
|
5349
5508
|
}
|
|
5350
5509
|
return results;
|
|
5351
5510
|
}
|
|
5352
|
-
var import_child_process2,
|
|
5511
|
+
var import_child_process2, import_fs8, import_os2, path10, BUILTIN_IDE_DEFINITIONS, registeredIDEs;
|
|
5353
5512
|
var init_ide_detector = __esm({
|
|
5354
5513
|
"../../oss/packages/daemon-core/src/detection/ide-detector.ts"() {
|
|
5355
5514
|
"use strict";
|
|
5356
5515
|
import_child_process2 = require("child_process");
|
|
5357
|
-
|
|
5516
|
+
import_fs8 = require("fs");
|
|
5358
5517
|
import_os2 = require("os");
|
|
5359
5518
|
path10 = __toESM(require("path"));
|
|
5360
5519
|
BUILTIN_IDE_DEFINITIONS = [];
|
|
@@ -37802,7 +37961,7 @@ function commandExists(command) {
|
|
|
37802
37961
|
const trimmed = command.trim();
|
|
37803
37962
|
if (!trimmed) return false;
|
|
37804
37963
|
if (isExplicitCommand(trimmed)) {
|
|
37805
|
-
return (0,
|
|
37964
|
+
return (0, import_fs9.existsSync)(expandExecutable(trimmed));
|
|
37806
37965
|
}
|
|
37807
37966
|
try {
|
|
37808
37967
|
(0, import_child_process6.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], {
|
|
@@ -37823,10 +37982,10 @@ function hasCliArg(args, flag) {
|
|
|
37823
37982
|
}
|
|
37824
37983
|
function ensureEmptyDelegatedMcpConfig(workspace) {
|
|
37825
37984
|
const baseDir = path19.join(os16.tmpdir(), "adhdev-delegated-agent-empty-mcp");
|
|
37826
|
-
(0,
|
|
37985
|
+
(0, import_fs9.mkdirSync)(baseDir, { recursive: true });
|
|
37827
37986
|
const workspaceHash = crypto4.createHash("sha256").update(path19.resolve(workspace || os16.tmpdir())).digest("hex").slice(0, 16);
|
|
37828
37987
|
const filePath = path19.join(baseDir, `${workspaceHash}.json`);
|
|
37829
|
-
(0,
|
|
37988
|
+
(0, import_fs9.writeFileSync)(filePath, JSON.stringify({ mcpServers: {} }, null, 2), "utf-8");
|
|
37830
37989
|
return filePath;
|
|
37831
37990
|
}
|
|
37832
37991
|
function buildCoordinatorDelegatedCliLaunchOptions(input) {
|
|
@@ -37953,14 +38112,14 @@ function resolveCliSessionBinding(provider, normalizedType, cliArgs, requestedRe
|
|
|
37953
38112
|
launchMode: "new"
|
|
37954
38113
|
};
|
|
37955
38114
|
}
|
|
37956
|
-
var os16, path19, crypto4,
|
|
38115
|
+
var os16, path19, crypto4, import_fs9, import_child_process6, chalkModule, chalkApi, COORDINATOR_DELEGATED_ENV_UNSETS, DaemonCliManager;
|
|
37957
38116
|
var init_cli_manager = __esm({
|
|
37958
38117
|
"../../oss/packages/daemon-core/src/commands/cli-manager.ts"() {
|
|
37959
38118
|
"use strict";
|
|
37960
38119
|
os16 = __toESM(require("os"));
|
|
37961
38120
|
path19 = __toESM(require("path"));
|
|
37962
38121
|
crypto4 = __toESM(require("crypto"));
|
|
37963
|
-
|
|
38122
|
+
import_fs9 = require("fs");
|
|
37964
38123
|
import_child_process6 = require("child_process");
|
|
37965
38124
|
init_source2();
|
|
37966
38125
|
init_provider_cli_adapter();
|
|
@@ -38874,7 +39033,7 @@ function createFsWatchInstance(path42, options, listener, errHandler, emitRaw) {
|
|
|
38874
39033
|
}
|
|
38875
39034
|
};
|
|
38876
39035
|
try {
|
|
38877
|
-
return (0,
|
|
39036
|
+
return (0, import_fs10.watch)(path42, {
|
|
38878
39037
|
persistent: options.persistent
|
|
38879
39038
|
}, handleEvent);
|
|
38880
39039
|
} catch (error48) {
|
|
@@ -38882,11 +39041,11 @@ function createFsWatchInstance(path42, options, listener, errHandler, emitRaw) {
|
|
|
38882
39041
|
return void 0;
|
|
38883
39042
|
}
|
|
38884
39043
|
}
|
|
38885
|
-
var
|
|
39044
|
+
var import_fs10, import_promises5, sysPath, import_os3, STR_DATA, STR_END, STR_CLOSE, EMPTY_FN, pl, isWindows, isMacos, isLinux, isFreeBSD, isIBMi, EVENTS, EV, THROTTLE_MODE_WATCH, statMethods, KEY_LISTENERS, KEY_ERR, KEY_RAW, HANDLER_KEYS, binaryExtensions, isBinaryPath, foreach, addAndConvert, clearItem, delFromSet, isEmptySet, FsWatchInstances, fsWatchBroadcast, setFsWatchListener, FsWatchFileInstances, setFsWatchFileListener, NodeFsHandler;
|
|
38886
39045
|
var init_handler2 = __esm({
|
|
38887
39046
|
"../../oss/node_modules/chokidar/esm/handler.js"() {
|
|
38888
39047
|
"use strict";
|
|
38889
|
-
|
|
39048
|
+
import_fs10 = require("fs");
|
|
38890
39049
|
import_promises5 = require("fs/promises");
|
|
38891
39050
|
sysPath = __toESM(require("path"), 1);
|
|
38892
39051
|
import_os3 = require("os");
|
|
@@ -39290,7 +39449,7 @@ var init_handler2 = __esm({
|
|
|
39290
39449
|
let cont = FsWatchFileInstances.get(fullPath);
|
|
39291
39450
|
const copts = cont && cont.options;
|
|
39292
39451
|
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
|
39293
|
-
(0,
|
|
39452
|
+
(0, import_fs10.unwatchFile)(fullPath);
|
|
39294
39453
|
cont = void 0;
|
|
39295
39454
|
}
|
|
39296
39455
|
if (cont) {
|
|
@@ -39301,7 +39460,7 @@ var init_handler2 = __esm({
|
|
|
39301
39460
|
listeners: listener,
|
|
39302
39461
|
rawEmitters: rawEmitter,
|
|
39303
39462
|
options,
|
|
39304
|
-
watcher: (0,
|
|
39463
|
+
watcher: (0, import_fs10.watchFile)(fullPath, options, (curr, prev) => {
|
|
39305
39464
|
foreach(cont.rawEmitters, (rawEmitter2) => {
|
|
39306
39465
|
rawEmitter2(EV.CHANGE, fullPath, { curr, prev });
|
|
39307
39466
|
});
|
|
@@ -39318,7 +39477,7 @@ var init_handler2 = __esm({
|
|
|
39318
39477
|
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
39319
39478
|
if (isEmptySet(cont.listeners)) {
|
|
39320
39479
|
FsWatchFileInstances.delete(fullPath);
|
|
39321
|
-
(0,
|
|
39480
|
+
(0, import_fs10.unwatchFile)(fullPath);
|
|
39322
39481
|
cont.options = cont.watcher = void 0;
|
|
39323
39482
|
Object.freeze(cont);
|
|
39324
39483
|
}
|
|
@@ -39696,11 +39855,11 @@ function watch(paths, options = {}) {
|
|
|
39696
39855
|
watcher.add(paths);
|
|
39697
39856
|
return watcher;
|
|
39698
39857
|
}
|
|
39699
|
-
var
|
|
39858
|
+
var import_fs11, import_promises6, import_events2, sysPath2, SLASH, SLASH_SLASH, ONE_DOT, TWO_DOTS, STRING_TYPE, BACK_SLASH_RE, DOUBLE_SLASH_RE, DOT_RE, REPLACER_RE, isMatcherObject, unifyPaths, toUnix, normalizePathToUnix, normalizeIgnored, getAbsolutePath, EMPTY_SET, DirEntry, STAT_METHOD_F, STAT_METHOD_L, WatchHelper, FSWatcher;
|
|
39700
39859
|
var init_esm2 = __esm({
|
|
39701
39860
|
"../../oss/node_modules/chokidar/esm/index.js"() {
|
|
39702
39861
|
"use strict";
|
|
39703
|
-
|
|
39862
|
+
import_fs11 = require("fs");
|
|
39704
39863
|
import_promises6 = require("fs/promises");
|
|
39705
39864
|
import_events2 = require("events");
|
|
39706
39865
|
sysPath2 = __toESM(require("path"), 1);
|
|
@@ -40178,7 +40337,7 @@ var init_esm2 = __esm({
|
|
|
40178
40337
|
const now = /* @__PURE__ */ new Date();
|
|
40179
40338
|
const writes = this._pendingWrites;
|
|
40180
40339
|
function awaitWriteFinishFn(prevStat) {
|
|
40181
|
-
(0,
|
|
40340
|
+
(0, import_fs11.stat)(fullPath, (err, curStat) => {
|
|
40182
40341
|
if (err || !writes.has(path42)) {
|
|
40183
40342
|
if (err && err.code !== "ENOENT")
|
|
40184
40343
|
awfEmit(err);
|
|
@@ -46855,7 +47014,7 @@ function truncateValidationOutput(value) {
|
|
|
46855
47014
|
}
|
|
46856
47015
|
function readPackageScripts(workspace) {
|
|
46857
47016
|
try {
|
|
46858
|
-
const packageJsonPath = (0,
|
|
47017
|
+
const packageJsonPath = (0, import_path7.join)(workspace, "package.json");
|
|
46859
47018
|
const parsed = JSON.parse(fs10.readFileSync(packageJsonPath, "utf-8"));
|
|
46860
47019
|
return parsed?.scripts && typeof parsed.scripts === "object" && !Array.isArray(parsed.scripts) ? parsed.scripts : {};
|
|
46861
47020
|
} catch {
|
|
@@ -47063,13 +47222,13 @@ function serializeMeshCoordinatorMcpConfig(config2, format) {
|
|
|
47063
47222
|
}
|
|
47064
47223
|
function resolveHermesUserHome() {
|
|
47065
47224
|
const explicitHome = process.env.HERMES_HOME?.trim();
|
|
47066
|
-
return explicitHome || (0,
|
|
47225
|
+
return explicitHome || (0, import_path7.join)((0, import_os4.homedir)(), ".hermes");
|
|
47067
47226
|
}
|
|
47068
47227
|
function loadHermesCoordinatorBaseConfig(targetConfigPath) {
|
|
47069
47228
|
const sourceHome = resolveHermesUserHome();
|
|
47070
|
-
const sourceConfigPath = (0,
|
|
47229
|
+
const sourceConfigPath = (0, import_path7.join)(sourceHome, "config.yaml");
|
|
47071
47230
|
if (!fs10.existsSync(sourceConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
47072
|
-
if ((0,
|
|
47231
|
+
if ((0, import_path7.resolve)(sourceConfigPath) === (0, import_path7.resolve)(targetConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
47073
47232
|
const parsed = parseMeshCoordinatorMcpConfig(fs10.readFileSync(sourceConfigPath, "utf-8"), "hermes_config_yaml");
|
|
47074
47233
|
const { mcp_servers: _mcpServers, ...baseConfig } = parsed;
|
|
47075
47234
|
return { config: baseConfig, sourceHome, sourceConfigPath };
|
|
@@ -47103,10 +47262,10 @@ function stripHermesCoordinatorTempModelProviderOverrides(config2) {
|
|
|
47103
47262
|
return sanitized;
|
|
47104
47263
|
}
|
|
47105
47264
|
function copyHermesCoordinatorCredentialFiles(sourceHome, targetHome) {
|
|
47106
|
-
if ((0,
|
|
47265
|
+
if ((0, import_path7.resolve)(sourceHome) === (0, import_path7.resolve)(targetHome)) return;
|
|
47107
47266
|
for (const fileName of [".env", "auth.json"]) {
|
|
47108
|
-
const sourcePath = (0,
|
|
47109
|
-
const targetPath = (0,
|
|
47267
|
+
const sourcePath = (0, import_path7.join)(sourceHome, fileName);
|
|
47268
|
+
const targetPath = (0, import_path7.join)(targetHome, fileName);
|
|
47110
47269
|
if (!fs10.existsSync(sourcePath)) continue;
|
|
47111
47270
|
try {
|
|
47112
47271
|
fs10.copyFileSync(sourcePath, targetPath);
|
|
@@ -47196,7 +47355,7 @@ function summarizeSessionHostPruneResult(result) {
|
|
|
47196
47355
|
keptCount: Array.isArray(value.keptSessionIds) ? value.keptSessionIds.length : void 0
|
|
47197
47356
|
};
|
|
47198
47357
|
}
|
|
47199
|
-
var import_os4,
|
|
47358
|
+
var import_os4, import_path7, fs10, CHANNEL_NPM_TAG, CHANNEL_SERVER_URL, REFINE_VALIDATION_CATEGORIES, REFINE_VALIDATION_TIMEOUT_MS, REFINE_VALIDATION_OUTPUT_LIMIT_BYTES, REFINE_VALIDATION_SUMMARY_CHARS, REFINE_VALIDATION_MAX_COMMANDS, CHAT_COMMANDS, READ_DEBUG_ENABLED2, DaemonCommandRouter;
|
|
47200
47359
|
var init_router = __esm({
|
|
47201
47360
|
"../../oss/packages/daemon-core/src/commands/router.ts"() {
|
|
47202
47361
|
"use strict";
|
|
@@ -47226,7 +47385,7 @@ var init_router = __esm({
|
|
|
47226
47385
|
init_snapshot();
|
|
47227
47386
|
init_upgrade_helper();
|
|
47228
47387
|
import_os4 = require("os");
|
|
47229
|
-
|
|
47388
|
+
import_path7 = require("path");
|
|
47230
47389
|
fs10 = __toESM(require("fs"));
|
|
47231
47390
|
CHANNEL_NPM_TAG = { stable: "latest", preview: "next" };
|
|
47232
47391
|
CHANNEL_SERVER_URL = {
|
|
@@ -47355,7 +47514,7 @@ var init_router = __esm({
|
|
|
47355
47514
|
}
|
|
47356
47515
|
const { resolveWorktreePath: resolveWorktreePath2, listWorktrees: listWorktrees2, removeWorktree: removeWorktree2 } = await Promise.resolve().then(() => (init_git_worktree(), git_worktree_exports));
|
|
47357
47516
|
const normalizePath3 = (value) => {
|
|
47358
|
-
const resolved = (0,
|
|
47517
|
+
const resolved = (0, import_path7.resolve)(value);
|
|
47359
47518
|
try {
|
|
47360
47519
|
return fs10.realpathSync(resolved);
|
|
47361
47520
|
} catch {
|
|
@@ -47756,7 +47915,8 @@ var init_router = __esm({
|
|
|
47756
47915
|
return handleMeshForwardEvent({ instanceManager: this.deps.instanceManager }, args);
|
|
47757
47916
|
}
|
|
47758
47917
|
case "get_pending_mesh_events": {
|
|
47759
|
-
const
|
|
47918
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
47919
|
+
const events = drainPendingMeshCoordinatorEvents(meshId || void 0);
|
|
47760
47920
|
return { success: true, events };
|
|
47761
47921
|
}
|
|
47762
47922
|
case "launch_cli":
|
|
@@ -48977,7 +49137,7 @@ ${block}`);
|
|
|
48977
49137
|
workspace
|
|
48978
49138
|
};
|
|
48979
49139
|
}
|
|
48980
|
-
const { existsSync:
|
|
49140
|
+
const { existsSync: existsSync33, readFileSync: readFileSync24, writeFileSync: writeFileSync18, copyFileSync: copyFileSync5, mkdirSync: mkdirSync22 } = await import("fs");
|
|
48981
49141
|
const { dirname: dirname13 } = await import("path");
|
|
48982
49142
|
const mcpConfigPath = coordinatorSetup.configPath;
|
|
48983
49143
|
const hermesManualFallback = cliType === "hermes-cli" && configFormat === "hermes_config_yaml" ? createHermesManualMeshCoordinatorSetup(meshId, workspace) : null;
|
|
@@ -49020,14 +49180,14 @@ ${block}`);
|
|
|
49020
49180
|
if (hermesManualFallback) return returnManualFallback(message);
|
|
49021
49181
|
return { success: false, code: "mesh_coordinator_config_write_failed", error: message, meshId, cliType, workspace };
|
|
49022
49182
|
}
|
|
49023
|
-
const hadExistingMcpConfig =
|
|
49183
|
+
const hadExistingMcpConfig = existsSync33(mcpConfigPath);
|
|
49024
49184
|
let existingMcpConfig = hermesBaseConfig?.config || {};
|
|
49025
49185
|
if (hermesBaseConfig) {
|
|
49026
49186
|
copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome, dirname13(mcpConfigPath));
|
|
49027
49187
|
}
|
|
49028
49188
|
if (hadExistingMcpConfig) {
|
|
49029
49189
|
try {
|
|
49030
|
-
const parsedExistingMcpConfig = parseMeshCoordinatorMcpConfig(
|
|
49190
|
+
const parsedExistingMcpConfig = parseMeshCoordinatorMcpConfig(readFileSync24(mcpConfigPath, "utf-8"), configFormat);
|
|
49031
49191
|
const existingCoordinatorConfig = hermesManualFallback ? stripHermesCoordinatorTempModelProviderOverrides(parsedExistingMcpConfig) : parsedExistingMcpConfig;
|
|
49032
49192
|
existingMcpConfig = { ...existingMcpConfig, ...existingCoordinatorConfig };
|
|
49033
49193
|
copyFileSync5(mcpConfigPath, mcpConfigPath + ".backup");
|
|
@@ -49215,29 +49375,48 @@ ${block}`);
|
|
|
49215
49375
|
}
|
|
49216
49376
|
if (workspace) {
|
|
49217
49377
|
if (!fs10.existsSync(workspace)) {
|
|
49218
|
-
|
|
49219
|
-
|
|
49220
|
-
|
|
49221
|
-
|
|
49222
|
-
|
|
49223
|
-
|
|
49224
|
-
|
|
49225
|
-
|
|
49226
|
-
|
|
49378
|
+
let remoteProbeApplied = false;
|
|
49379
|
+
if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
|
|
49380
|
+
try {
|
|
49381
|
+
const remoteResult = await Promise.race([
|
|
49382
|
+
this.deps.dispatchMeshCommand(daemonId, "git_status", { workspace }),
|
|
49383
|
+
new Promise((_2, reject) => setTimeout(() => reject(new Error("timeout")), 8e3))
|
|
49384
|
+
]);
|
|
49385
|
+
const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
|
|
49386
|
+
if (remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean") {
|
|
49387
|
+
status.git = remoteGit;
|
|
49388
|
+
status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
|
|
49389
|
+
remoteProbeApplied = true;
|
|
49390
|
+
}
|
|
49391
|
+
} catch {
|
|
49392
|
+
}
|
|
49227
49393
|
}
|
|
49228
|
-
|
|
49229
|
-
|
|
49230
|
-
|
|
49231
|
-
|
|
49232
|
-
|
|
49233
|
-
|
|
49234
|
-
|
|
49235
|
-
|
|
49236
|
-
|
|
49394
|
+
if (!remoteProbeApplied) {
|
|
49395
|
+
if (applyCachedInlineMeshNodeStatus(status, node)) {
|
|
49396
|
+
status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
|
|
49397
|
+
nodeStatuses.push(status);
|
|
49398
|
+
continue;
|
|
49399
|
+
}
|
|
49400
|
+
if (meshRecord?.source === "inline_cache" && !isSelfNode) {
|
|
49401
|
+
status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
|
|
49402
|
+
nodeStatuses.push(status);
|
|
49403
|
+
continue;
|
|
49404
|
+
}
|
|
49237
49405
|
}
|
|
49238
|
-
}
|
|
49239
|
-
|
|
49240
|
-
|
|
49406
|
+
} else {
|
|
49407
|
+
try {
|
|
49408
|
+
const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
|
|
49409
|
+
status.git = gitStatus;
|
|
49410
|
+
if (gitStatus.isGitRepo) {
|
|
49411
|
+
status.health = deriveMeshNodeHealthFromGit(gitStatus);
|
|
49412
|
+
} else {
|
|
49413
|
+
status.health = "degraded";
|
|
49414
|
+
if (gitStatus.error && !status.error) status.error = gitStatus.error;
|
|
49415
|
+
}
|
|
49416
|
+
} catch {
|
|
49417
|
+
if (!applyCachedInlineMeshNodeStatus(status, node)) {
|
|
49418
|
+
status.health = "degraded";
|
|
49419
|
+
}
|
|
49241
49420
|
}
|
|
49242
49421
|
}
|
|
49243
49422
|
} else {
|
|
@@ -58095,7 +58274,7 @@ var require_yoctocolors_cjs = __commonJS({
|
|
|
58095
58274
|
}
|
|
58096
58275
|
});
|
|
58097
58276
|
|
|
58098
|
-
// ../../node_modules/@inquirer/figures/dist/esm/index.
|
|
58277
|
+
// ../../node_modules/@inquirer/figures/dist/esm/index.js
|
|
58099
58278
|
function isUnicodeSupported() {
|
|
58100
58279
|
if (import_node_process3.default.platform !== "win32") {
|
|
58101
58280
|
return import_node_process3.default.env["TERM"] !== "linux";
|
|
@@ -58107,7 +58286,7 @@ function isUnicodeSupported() {
|
|
|
58107
58286
|
}
|
|
58108
58287
|
var import_node_process3, common2, specialMainSymbols, specialFallbackSymbols, mainSymbols, fallbackSymbols, shouldUseMain, figures, esm_default, replacements;
|
|
58109
58288
|
var init_esm3 = __esm({
|
|
58110
|
-
"../../node_modules/@inquirer/figures/dist/esm/index.
|
|
58289
|
+
"../../node_modules/@inquirer/figures/dist/esm/index.js"() {
|
|
58111
58290
|
"use strict";
|
|
58112
58291
|
import_node_process3 = __toESM(require("process"), 1);
|
|
58113
58292
|
common2 = {
|
|
@@ -58378,7 +58557,10 @@ var init_esm3 = __esm({
|
|
|
58378
58557
|
oneNinth: "1/9",
|
|
58379
58558
|
oneTenth: "1/10"
|
|
58380
58559
|
};
|
|
58381
|
-
mainSymbols = {
|
|
58560
|
+
mainSymbols = {
|
|
58561
|
+
...common2,
|
|
58562
|
+
...specialMainSymbols
|
|
58563
|
+
};
|
|
58382
58564
|
fallbackSymbols = {
|
|
58383
58565
|
...common2,
|
|
58384
58566
|
...specialFallbackSymbols
|
|
@@ -72538,7 +72720,7 @@ var require_buffer_list = __commonJS({
|
|
|
72538
72720
|
}
|
|
72539
72721
|
}, {
|
|
72540
72722
|
key: "join",
|
|
72541
|
-
value: function
|
|
72723
|
+
value: function join40(s) {
|
|
72542
72724
|
if (this.length === 0) return "";
|
|
72543
72725
|
var p = this.head;
|
|
72544
72726
|
var ret = "" + p.data;
|
|
@@ -86597,13 +86779,13 @@ function splitStringBySpace(str2) {
|
|
|
86597
86779
|
}
|
|
86598
86780
|
return pieces;
|
|
86599
86781
|
}
|
|
86600
|
-
var import_chardet, import_child_process12,
|
|
86782
|
+
var import_chardet, import_child_process12, import_fs12, import_node_path3, import_node_os3, import_node_crypto3, import_iconv_lite, ExternalEditor;
|
|
86601
86783
|
var init_esm4 = __esm({
|
|
86602
86784
|
"../../node_modules/@inquirer/external-editor/dist/esm/index.js"() {
|
|
86603
86785
|
"use strict";
|
|
86604
86786
|
import_chardet = __toESM(require_lib(), 1);
|
|
86605
86787
|
import_child_process12 = require("child_process");
|
|
86606
|
-
|
|
86788
|
+
import_fs12 = require("fs");
|
|
86607
86789
|
import_node_path3 = __toESM(require("path"), 1);
|
|
86608
86790
|
import_node_os3 = __toESM(require("os"), 1);
|
|
86609
86791
|
import_node_crypto3 = require("crypto");
|
|
@@ -86679,14 +86861,14 @@ var init_esm4 = __esm({
|
|
|
86679
86861
|
if (Object.prototype.hasOwnProperty.call(this.fileOptions, "mode")) {
|
|
86680
86862
|
opt.mode = this.fileOptions.mode;
|
|
86681
86863
|
}
|
|
86682
|
-
(0,
|
|
86864
|
+
(0, import_fs12.writeFileSync)(this.tempFile, this.text, opt);
|
|
86683
86865
|
} catch (createFileError) {
|
|
86684
86866
|
throw new CreateFileError(createFileError);
|
|
86685
86867
|
}
|
|
86686
86868
|
}
|
|
86687
86869
|
readTemporaryFile() {
|
|
86688
86870
|
try {
|
|
86689
|
-
const tempFileBuffer = (0,
|
|
86871
|
+
const tempFileBuffer = (0, import_fs12.readFileSync)(this.tempFile);
|
|
86690
86872
|
if (tempFileBuffer.length === 0) {
|
|
86691
86873
|
this.text = "";
|
|
86692
86874
|
} else {
|
|
@@ -86702,7 +86884,7 @@ var init_esm4 = __esm({
|
|
|
86702
86884
|
}
|
|
86703
86885
|
removeTemporaryFile() {
|
|
86704
86886
|
try {
|
|
86705
|
-
(0,
|
|
86887
|
+
(0, import_fs12.unlinkSync)(this.tempFile);
|
|
86706
86888
|
} catch (removeFileError) {
|
|
86707
86889
|
throw new RemoveFileError(removeFileError);
|
|
86708
86890
|
}
|
|
@@ -88404,25 +88586,25 @@ function resolvePackageVersion(options) {
|
|
|
88404
88586
|
const injectedVersion = options?.injectedVersion || "unknown";
|
|
88405
88587
|
const dir = options?.dirname || __dirname;
|
|
88406
88588
|
const possiblePaths = [
|
|
88407
|
-
(0,
|
|
88408
|
-
(0,
|
|
88409
|
-
(0,
|
|
88589
|
+
(0, import_path8.join)(dir, "..", "..", "package.json"),
|
|
88590
|
+
(0, import_path8.join)(dir, "..", "package.json"),
|
|
88591
|
+
(0, import_path8.join)(dir, "package.json")
|
|
88410
88592
|
];
|
|
88411
88593
|
for (const p of possiblePaths) {
|
|
88412
88594
|
try {
|
|
88413
|
-
const data = JSON.parse((0,
|
|
88595
|
+
const data = JSON.parse((0, import_fs13.readFileSync)(p, "utf-8"));
|
|
88414
88596
|
if (data.version) return data.version;
|
|
88415
88597
|
} catch {
|
|
88416
88598
|
}
|
|
88417
88599
|
}
|
|
88418
88600
|
return injectedVersion;
|
|
88419
88601
|
}
|
|
88420
|
-
var
|
|
88602
|
+
var import_fs13, import_path8;
|
|
88421
88603
|
var init_version = __esm({
|
|
88422
88604
|
"src/version.ts"() {
|
|
88423
88605
|
"use strict";
|
|
88424
|
-
|
|
88425
|
-
|
|
88606
|
+
import_fs13 = require("fs");
|
|
88607
|
+
import_path8 = require("path");
|
|
88426
88608
|
}
|
|
88427
88609
|
});
|
|
88428
88610
|
|
|
@@ -90358,7 +90540,7 @@ var require_filesystem = __commonJS({
|
|
|
90358
90540
|
var LDD_PATH = "/usr/bin/ldd";
|
|
90359
90541
|
var SELF_PATH = "/proc/self/exe";
|
|
90360
90542
|
var MAX_LENGTH = 2048;
|
|
90361
|
-
var
|
|
90543
|
+
var readFileSync24 = (path42) => {
|
|
90362
90544
|
const fd = fs24.openSync(path42, "r");
|
|
90363
90545
|
const buffer = Buffer.alloc(MAX_LENGTH);
|
|
90364
90546
|
const bytesRead = fs24.readSync(fd, buffer, 0, MAX_LENGTH, 0);
|
|
@@ -90383,7 +90565,7 @@ var require_filesystem = __commonJS({
|
|
|
90383
90565
|
module2.exports = {
|
|
90384
90566
|
LDD_PATH,
|
|
90385
90567
|
SELF_PATH,
|
|
90386
|
-
readFileSync:
|
|
90568
|
+
readFileSync: readFileSync24,
|
|
90387
90569
|
readFile: readFile2
|
|
90388
90570
|
};
|
|
90389
90571
|
}
|
|
@@ -90432,7 +90614,7 @@ var require_detect_libc = __commonJS({
|
|
|
90432
90614
|
"use strict";
|
|
90433
90615
|
var childProcess = require("child_process");
|
|
90434
90616
|
var { isLinux: isLinux2, getReport } = require_process();
|
|
90435
|
-
var { LDD_PATH, SELF_PATH, readFile: readFile2, readFileSync:
|
|
90617
|
+
var { LDD_PATH, SELF_PATH, readFile: readFile2, readFileSync: readFileSync24 } = require_filesystem();
|
|
90436
90618
|
var { interpreterPath } = require_elf();
|
|
90437
90619
|
var cachedFamilyInterpreter;
|
|
90438
90620
|
var cachedFamilyFilesystem;
|
|
@@ -90524,7 +90706,7 @@ var require_detect_libc = __commonJS({
|
|
|
90524
90706
|
}
|
|
90525
90707
|
cachedFamilyFilesystem = null;
|
|
90526
90708
|
try {
|
|
90527
|
-
const lddContent =
|
|
90709
|
+
const lddContent = readFileSync24(LDD_PATH);
|
|
90528
90710
|
cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
|
|
90529
90711
|
} catch (e) {
|
|
90530
90712
|
}
|
|
@@ -90549,7 +90731,7 @@ var require_detect_libc = __commonJS({
|
|
|
90549
90731
|
}
|
|
90550
90732
|
cachedFamilyInterpreter = null;
|
|
90551
90733
|
try {
|
|
90552
|
-
const selfContent =
|
|
90734
|
+
const selfContent = readFileSync24(SELF_PATH);
|
|
90553
90735
|
const path42 = interpreterPath(selfContent);
|
|
90554
90736
|
cachedFamilyInterpreter = familyFromInterpreterPath(path42);
|
|
90555
90737
|
} catch (e) {
|
|
@@ -90613,7 +90795,7 @@ var require_detect_libc = __commonJS({
|
|
|
90613
90795
|
}
|
|
90614
90796
|
cachedVersionFilesystem = null;
|
|
90615
90797
|
try {
|
|
90616
|
-
const lddContent =
|
|
90798
|
+
const lddContent = readFileSync24(LDD_PATH);
|
|
90617
90799
|
const versionMatch = lddContent.match(RE_GLIBC_VERSION);
|
|
90618
90800
|
if (versionMatch) {
|
|
90619
90801
|
cachedVersionFilesystem = versionMatch[1];
|
|
@@ -98283,7 +98465,7 @@ var init_adhdev_daemon = __esm({
|
|
|
98283
98465
|
init_version();
|
|
98284
98466
|
init_src();
|
|
98285
98467
|
init_runtime_defaults();
|
|
98286
|
-
pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.
|
|
98468
|
+
pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.25" });
|
|
98287
98469
|
AdhdevDaemon = class _AdhdevDaemon {
|
|
98288
98470
|
localHttpServer = null;
|
|
98289
98471
|
localWss = null;
|
|
@@ -99177,6 +99359,7 @@ ${err?.stack || ""}`);
|
|
|
99177
99359
|
const meshId = this.readMeshString(settings.meshNodeFor);
|
|
99178
99360
|
const coordinatorDaemonId = this.readMeshString(settings.meshCoordinatorDaemonId);
|
|
99179
99361
|
if (!meshId || !coordinatorDaemonId) return;
|
|
99362
|
+
const relayTimestamp = typeof event.timestamp === "number" && Number.isFinite(event.timestamp) ? event.timestamp : this.readMeshString(event.timestamp) || void 0;
|
|
99180
99363
|
const payload = {
|
|
99181
99364
|
event: this.readMeshString(event.event),
|
|
99182
99365
|
meshId,
|
|
@@ -99185,7 +99368,8 @@ ${err?.stack || ""}`);
|
|
|
99185
99368
|
targetSessionId: this.readMeshString(event.targetSessionId) || instanceId,
|
|
99186
99369
|
providerType: this.readMeshString(event.providerType),
|
|
99187
99370
|
providerSessionId: this.readMeshString(event.providerSessionId),
|
|
99188
|
-
finalSummary: this.readMeshString(event.finalSummary) || this.readMeshString(event.summary)
|
|
99371
|
+
finalSummary: this.readMeshString(event.finalSummary) || this.readMeshString(event.summary),
|
|
99372
|
+
...relayTimestamp !== void 0 ? { timestamp: relayTimestamp } : {}
|
|
99189
99373
|
};
|
|
99190
99374
|
if (coordinatorDaemonId === localDaemonId) {
|
|
99191
99375
|
try {
|
|
@@ -99211,7 +99395,8 @@ ${err?.stack || ""}`);
|
|
|
99211
99395
|
providerType: payload.providerType,
|
|
99212
99396
|
providerSessionId: payload.providerSessionId,
|
|
99213
99397
|
finalSummary: payload.finalSummary,
|
|
99214
|
-
workspace: payload.workspace
|
|
99398
|
+
workspace: payload.workspace,
|
|
99399
|
+
...payload.timestamp !== void 0 ? { timestamp: payload.timestamp } : {}
|
|
99215
99400
|
},
|
|
99216
99401
|
queuedAt: Date.now()
|
|
99217
99402
|
});
|