adhdev 0.9.82-rc.3 → 0.9.82-rc.30
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 +1465 -716
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +984 -326
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/vendor/mcp-server/index.js +324 -31
- package/vendor/mcp-server/index.js.map +1 -1
package/dist/index.js
CHANGED
|
@@ -264,8 +264,14 @@ async function getGitRepoStatus(workspace, options = {}) {
|
|
|
264
264
|
const includeSubmodules = options.includeSubmodules !== false;
|
|
265
265
|
try {
|
|
266
266
|
const repo = await resolveGitRepository(workspace, options);
|
|
267
|
-
|
|
268
|
-
|
|
267
|
+
let parsed = await readPorcelainStatus(repo, options);
|
|
268
|
+
let upstreamProbe = getInitialUpstreamProbe(parsed);
|
|
269
|
+
if (options.refreshUpstream) {
|
|
270
|
+
upstreamProbe = await refreshTrackedUpstream(repo, parsed, options);
|
|
271
|
+
if (upstreamProbe.upstreamStatus === "fresh") {
|
|
272
|
+
parsed = await readPorcelainStatus(repo, options);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
269
275
|
const head = await readHead(repo, options);
|
|
270
276
|
const stashCount = await readStashCount(repo, options);
|
|
271
277
|
let submodules;
|
|
@@ -280,6 +286,9 @@ async function getGitRepoStatus(workspace, options = {}) {
|
|
|
280
286
|
headCommit: head.commit,
|
|
281
287
|
headMessage: head.message,
|
|
282
288
|
upstream: parsed.upstream,
|
|
289
|
+
upstreamStatus: parsed.upstream ? upstreamProbe.upstreamStatus : "no_upstream",
|
|
290
|
+
upstreamFetchedAt: upstreamProbe.upstreamFetchedAt,
|
|
291
|
+
upstreamFetchError: upstreamProbe.upstreamFetchError,
|
|
283
292
|
ahead: parsed.ahead,
|
|
284
293
|
behind: parsed.behind,
|
|
285
294
|
staged: parsed.staged,
|
|
@@ -304,6 +313,60 @@ async function getGitRepoStatus(workspace, options = {}) {
|
|
|
304
313
|
);
|
|
305
314
|
}
|
|
306
315
|
}
|
|
316
|
+
async function readPorcelainStatus(repo, options) {
|
|
317
|
+
const statusOutput = await runGit(repo, ["status", "--porcelain=v2", "--branch"], options);
|
|
318
|
+
return parsePorcelainV2Status(statusOutput.stdout);
|
|
319
|
+
}
|
|
320
|
+
function getInitialUpstreamProbe(parsed) {
|
|
321
|
+
return {
|
|
322
|
+
upstreamStatus: parsed.upstream ? "unchecked" : "no_upstream"
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
async function refreshTrackedUpstream(repo, parsed, options) {
|
|
326
|
+
if (!parsed.upstream || !parsed.branch) {
|
|
327
|
+
return { upstreamStatus: "no_upstream" };
|
|
328
|
+
}
|
|
329
|
+
const remoteName = await readBranchRemote(repo, parsed.branch, options) ?? inferRemoteName(parsed.upstream);
|
|
330
|
+
if (!remoteName) {
|
|
331
|
+
return {
|
|
332
|
+
upstreamStatus: "stale",
|
|
333
|
+
upstreamFetchError: `Unable to resolve remote for upstream '${parsed.upstream}'`
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
try {
|
|
337
|
+
await runGit(repo, ["fetch", "--quiet", "--prune", "--no-tags", remoteName], options);
|
|
338
|
+
return {
|
|
339
|
+
upstreamStatus: "fresh",
|
|
340
|
+
upstreamFetchedAt: Date.now()
|
|
341
|
+
};
|
|
342
|
+
} catch (error48) {
|
|
343
|
+
return {
|
|
344
|
+
upstreamStatus: "stale",
|
|
345
|
+
upstreamFetchError: formatGitError(error48)
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
async function readBranchRemote(repo, branch, options) {
|
|
350
|
+
try {
|
|
351
|
+
const result = await runGit(repo, ["config", "--get", `branch.${branch}.remote`], options);
|
|
352
|
+
return result.stdout.trim() || null;
|
|
353
|
+
} catch {
|
|
354
|
+
return null;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
function inferRemoteName(upstream) {
|
|
358
|
+
const [remoteName] = upstream.split("/");
|
|
359
|
+
return remoteName?.trim() || null;
|
|
360
|
+
}
|
|
361
|
+
function formatGitError(error48) {
|
|
362
|
+
if (error48 instanceof GitCommandError) {
|
|
363
|
+
return error48.stderr || error48.message;
|
|
364
|
+
}
|
|
365
|
+
if (error48 instanceof Error) {
|
|
366
|
+
return error48.message;
|
|
367
|
+
}
|
|
368
|
+
return String(error48);
|
|
369
|
+
}
|
|
307
370
|
function parsePorcelainV2Status(output) {
|
|
308
371
|
const parsed = {
|
|
309
372
|
branch: null,
|
|
@@ -398,6 +461,7 @@ function emptyStatus(workspace, lastCheckedAt, error48) {
|
|
|
398
461
|
headCommit: null,
|
|
399
462
|
headMessage: null,
|
|
400
463
|
upstream: null,
|
|
464
|
+
upstreamStatus: "unavailable",
|
|
401
465
|
ahead: 0,
|
|
402
466
|
behind: 0,
|
|
403
467
|
staged: 0,
|
|
@@ -690,6 +754,9 @@ function createGitCompactSummary(status, diffSummary) {
|
|
|
690
754
|
isGitRepo: status.isGitRepo,
|
|
691
755
|
repoRoot: status.repoRoot,
|
|
692
756
|
branch: status.branch,
|
|
757
|
+
upstreamStatus: status.upstreamStatus,
|
|
758
|
+
upstreamFetchedAt: status.upstreamFetchedAt,
|
|
759
|
+
upstreamFetchError: status.upstreamFetchError,
|
|
693
760
|
dirty: status.staged > 0 || status.modified > 0 || status.untracked > 0 || status.deleted > 0 || status.renamed > 0 || conflictCount > 0 || changedFiles > 0,
|
|
694
761
|
changedFiles,
|
|
695
762
|
ahead: status.ahead,
|
|
@@ -1017,7 +1084,7 @@ function serviceNotImplemented(command) {
|
|
|
1017
1084
|
}
|
|
1018
1085
|
function createDefaultGitCommandServices() {
|
|
1019
1086
|
return {
|
|
1020
|
-
getStatus: ({ workspace }) => getGitRepoStatus(workspace),
|
|
1087
|
+
getStatus: ({ workspace, refreshUpstream }) => getGitRepoStatus(workspace, { refreshUpstream }),
|
|
1021
1088
|
getDiffSummary: ({ workspace }) => getGitDiffSummary(workspace),
|
|
1022
1089
|
getDiffFile: ({ workspace, path: filePath }) => getGitFileDiff(workspace, filePath),
|
|
1023
1090
|
createSnapshot: ({ workspace, reason, sessionId, turnId }) => defaultSnapshotStore.create({
|
|
@@ -1102,7 +1169,7 @@ async function handleGitCommand(command, args, services = defaultGitCommandServi
|
|
|
1102
1169
|
switch (command) {
|
|
1103
1170
|
case "git_status": {
|
|
1104
1171
|
if (!services.getStatus) return serviceNotImplemented(command);
|
|
1105
|
-
const status = await runService(() => services.getStatus({ workspace }));
|
|
1172
|
+
const status = await runService(() => services.getStatus({ workspace, refreshUpstream: optionalBoolean(args?.refreshUpstream) }));
|
|
1106
1173
|
return "success" in status ? status : { success: true, status };
|
|
1107
1174
|
}
|
|
1108
1175
|
case "git_diff_summary": {
|
|
@@ -3223,6 +3290,36 @@ function getQueuePath(meshId) {
|
|
|
3223
3290
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
3224
3291
|
return (0, import_path4.join)(getLedgerDir(), `${safe}.queue.json`);
|
|
3225
3292
|
}
|
|
3293
|
+
function getLockPath(meshId) {
|
|
3294
|
+
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
3295
|
+
return (0, import_path4.join)(getLedgerDir(), `${safe}.queue.lock`);
|
|
3296
|
+
}
|
|
3297
|
+
function withQueueLock(meshId, fn) {
|
|
3298
|
+
const lockPath = getLockPath(meshId);
|
|
3299
|
+
let fd = -1;
|
|
3300
|
+
for (let i = 0; i < 10; i++) {
|
|
3301
|
+
try {
|
|
3302
|
+
fd = (0, import_fs4.openSync)(lockPath, "wx");
|
|
3303
|
+
break;
|
|
3304
|
+
} catch {
|
|
3305
|
+
const deadline = Date.now() + 30;
|
|
3306
|
+
while (Date.now() < deadline) {
|
|
3307
|
+
}
|
|
3308
|
+
}
|
|
3309
|
+
}
|
|
3310
|
+
try {
|
|
3311
|
+
return fn();
|
|
3312
|
+
} finally {
|
|
3313
|
+
if (fd !== -1) try {
|
|
3314
|
+
(0, import_fs4.closeSync)(fd);
|
|
3315
|
+
} catch {
|
|
3316
|
+
}
|
|
3317
|
+
try {
|
|
3318
|
+
(0, import_fs4.unlinkSync)(lockPath);
|
|
3319
|
+
} catch {
|
|
3320
|
+
}
|
|
3321
|
+
}
|
|
3322
|
+
}
|
|
3226
3323
|
function readQueue(meshId) {
|
|
3227
3324
|
const path35 = getQueuePath(meshId);
|
|
3228
3325
|
if (!(0, import_fs4.existsSync)(path35)) return [];
|
|
@@ -3238,20 +3335,22 @@ function writeQueue(meshId, queue) {
|
|
|
3238
3335
|
(0, import_fs4.writeFileSync)(path35, JSON.stringify(queue, null, 2), "utf-8");
|
|
3239
3336
|
}
|
|
3240
3337
|
function enqueueTask(meshId, message, opts) {
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3338
|
+
return withQueueLock(meshId, () => {
|
|
3339
|
+
const queue = readQueue(meshId);
|
|
3340
|
+
const entry = {
|
|
3341
|
+
id: (0, import_crypto5.randomUUID)(),
|
|
3342
|
+
meshId,
|
|
3343
|
+
message,
|
|
3344
|
+
status: "pending",
|
|
3345
|
+
targetNodeId: opts?.targetNodeId,
|
|
3346
|
+
targetSessionId: opts?.targetSessionId,
|
|
3347
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3348
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
3349
|
+
};
|
|
3350
|
+
queue.push(entry);
|
|
3351
|
+
writeQueue(meshId, queue);
|
|
3352
|
+
return entry;
|
|
3353
|
+
});
|
|
3255
3354
|
}
|
|
3256
3355
|
function getQueue(meshId, opts) {
|
|
3257
3356
|
let queue = readQueue(meshId);
|
|
@@ -3262,100 +3361,111 @@ function getQueue(meshId, opts) {
|
|
|
3262
3361
|
return queue;
|
|
3263
3362
|
}
|
|
3264
3363
|
function claimNextTask(meshId, nodeId, sessionId) {
|
|
3265
|
-
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
3278
|
-
|
|
3279
|
-
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3283
|
-
|
|
3364
|
+
return withQueueLock(meshId, () => {
|
|
3365
|
+
const queue = readQueue(meshId);
|
|
3366
|
+
const hasActiveAssignment = queue.some((q) => q.status === "assigned" && (q.assignedSessionId === sessionId || q.assignedNodeId === nodeId));
|
|
3367
|
+
if (hasActiveAssignment) return null;
|
|
3368
|
+
let targetIdx = queue.findIndex((q) => q.status === "pending" && q.targetSessionId === sessionId);
|
|
3369
|
+
if (targetIdx === -1) {
|
|
3370
|
+
targetIdx = queue.findIndex((q) => q.status === "pending" && q.targetNodeId === nodeId && !q.targetSessionId);
|
|
3371
|
+
}
|
|
3372
|
+
if (targetIdx === -1) {
|
|
3373
|
+
targetIdx = queue.findIndex((q) => q.status === "pending" && !q.targetNodeId && !q.targetSessionId);
|
|
3374
|
+
}
|
|
3375
|
+
if (targetIdx === -1) return null;
|
|
3376
|
+
const entry = queue[targetIdx];
|
|
3377
|
+
entry.status = "assigned";
|
|
3378
|
+
entry.assignedNodeId = nodeId;
|
|
3379
|
+
entry.assignedSessionId = sessionId;
|
|
3380
|
+
entry.dispatchTimestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
3381
|
+
entry.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3382
|
+
writeQueue(meshId, queue);
|
|
3383
|
+
return entry;
|
|
3384
|
+
});
|
|
3284
3385
|
}
|
|
3285
3386
|
function updateTaskStatus(meshId, taskId, status) {
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3387
|
+
return withQueueLock(meshId, () => {
|
|
3388
|
+
const queue = readQueue(meshId);
|
|
3389
|
+
const idx = queue.findIndex((q) => q.id === taskId);
|
|
3390
|
+
if (idx === -1) return null;
|
|
3391
|
+
queue[idx].status = status;
|
|
3392
|
+
queue[idx].updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3393
|
+
writeQueue(meshId, queue);
|
|
3394
|
+
return queue[idx];
|
|
3395
|
+
});
|
|
3293
3396
|
}
|
|
3294
3397
|
function recordTaskAutoLaunch(meshId, taskId, autoLaunch) {
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
...autoLaunch,
|
|
3301
|
-
updatedAt
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
return queue[idx];
|
|
3398
|
+
return withQueueLock(meshId, () => {
|
|
3399
|
+
const queue = readQueue(meshId);
|
|
3400
|
+
const idx = queue.findIndex((q) => q.id === taskId);
|
|
3401
|
+
if (idx === -1) return null;
|
|
3402
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3403
|
+
queue[idx].autoLaunch = { ...autoLaunch, updatedAt: now };
|
|
3404
|
+
queue[idx].updatedAt = now;
|
|
3405
|
+
writeQueue(meshId, queue);
|
|
3406
|
+
return queue[idx];
|
|
3407
|
+
});
|
|
3306
3408
|
}
|
|
3307
3409
|
function cancelTask(meshId, taskId, opts) {
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3410
|
+
return withQueueLock(meshId, () => {
|
|
3411
|
+
const queue = readQueue(meshId);
|
|
3412
|
+
const idx = queue.findIndex((q) => q.id === taskId);
|
|
3413
|
+
if (idx === -1) return null;
|
|
3414
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3415
|
+
queue[idx].status = "cancelled";
|
|
3416
|
+
queue[idx].updatedAt = now;
|
|
3417
|
+
queue[idx].cancelledAt = now;
|
|
3418
|
+
if (opts?.reason) queue[idx].cancelReason = opts.reason;
|
|
3419
|
+
writeQueue(meshId, queue);
|
|
3420
|
+
return queue[idx];
|
|
3421
|
+
});
|
|
3318
3422
|
}
|
|
3319
3423
|
function requeueTask(meshId, taskId, opts) {
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3333
|
-
|
|
3334
|
-
|
|
3335
|
-
|
|
3336
|
-
|
|
3337
|
-
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3424
|
+
return withQueueLock(meshId, () => {
|
|
3425
|
+
const queue = readQueue(meshId);
|
|
3426
|
+
const idx = queue.findIndex((q) => q.id === taskId);
|
|
3427
|
+
if (idx === -1) return null;
|
|
3428
|
+
const entry = queue[idx];
|
|
3429
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
3430
|
+
entry.status = "pending";
|
|
3431
|
+
delete entry.assignedNodeId;
|
|
3432
|
+
delete entry.assignedSessionId;
|
|
3433
|
+
delete entry.cancelledAt;
|
|
3434
|
+
delete entry.cancelReason;
|
|
3435
|
+
if (opts?.clearTargetNode) delete entry.targetNodeId;
|
|
3436
|
+
if (typeof opts?.targetNodeId === "string") entry.targetNodeId = opts.targetNodeId;
|
|
3437
|
+
if (opts?.clearTargetSession !== false) delete entry.targetSessionId;
|
|
3438
|
+
if (typeof opts?.targetSessionId === "string") entry.targetSessionId = opts.targetSessionId;
|
|
3439
|
+
entry.updatedAt = now;
|
|
3440
|
+
entry.requeuedAt = now;
|
|
3441
|
+
entry.requeueCount = (entry.requeueCount || 0) + 1;
|
|
3442
|
+
if (opts?.reason) entry.requeueReason = opts.reason;
|
|
3443
|
+
writeQueue(meshId, queue);
|
|
3444
|
+
return entry;
|
|
3445
|
+
});
|
|
3446
|
+
}
|
|
3447
|
+
function updateSessionTaskStatus(meshId, sessionId, status, opts) {
|
|
3448
|
+
return withQueueLock(meshId, () => {
|
|
3449
|
+
const queue = readQueue(meshId);
|
|
3450
|
+
const occurredAtTime = opts?.occurredAt ? new Date(opts.occurredAt).getTime() : Number.NaN;
|
|
3451
|
+
const hasOccurredAt = Number.isFinite(occurredAtTime);
|
|
3452
|
+
let bestIdx = -1;
|
|
3453
|
+
let bestTime = 0;
|
|
3454
|
+
for (let i = queue.length - 1; i >= 0; i--) {
|
|
3455
|
+
if (queue[i].assignedSessionId !== sessionId || queue[i].status !== "assigned") continue;
|
|
3347
3456
|
const time3 = new Date(queue[i].dispatchTimestamp || queue[i].updatedAt).getTime();
|
|
3457
|
+
if (hasOccurredAt && Number.isFinite(time3) && time3 > occurredAtTime) continue;
|
|
3348
3458
|
if (time3 > bestTime) {
|
|
3349
3459
|
bestTime = time3;
|
|
3350
3460
|
bestIdx = i;
|
|
3351
3461
|
}
|
|
3352
3462
|
}
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3463
|
+
if (bestIdx === -1) return null;
|
|
3464
|
+
queue[bestIdx].status = status;
|
|
3465
|
+
queue[bestIdx].updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
3466
|
+
writeQueue(meshId, queue);
|
|
3467
|
+
return queue[bestIdx];
|
|
3468
|
+
});
|
|
3359
3469
|
}
|
|
3360
3470
|
function getMeshQueueStats(meshId) {
|
|
3361
3471
|
const queue = readQueue(meshId);
|
|
@@ -3759,18 +3869,75 @@ __export(mesh_events_exports, {
|
|
|
3759
3869
|
drainPendingMeshCoordinatorEvents: () => drainPendingMeshCoordinatorEvents,
|
|
3760
3870
|
getPendingMeshCoordinatorEvents: () => getPendingMeshCoordinatorEvents,
|
|
3761
3871
|
handleMeshForwardEvent: () => handleMeshForwardEvent,
|
|
3872
|
+
queuePendingMeshCoordinatorEvent: () => queuePendingMeshCoordinatorEvent,
|
|
3762
3873
|
setupMeshEventForwarding: () => setupMeshEventForwarding,
|
|
3763
3874
|
triggerMeshQueue: () => triggerMeshQueue,
|
|
3764
3875
|
tryAssignQueueTask: () => tryAssignQueueTask
|
|
3765
3876
|
});
|
|
3766
|
-
function
|
|
3767
|
-
|
|
3877
|
+
function sweepExpiredRemoteIdleSessions() {
|
|
3878
|
+
const now = Date.now();
|
|
3879
|
+
for (const [key, session] of remoteIdleSessions) {
|
|
3880
|
+
if (session.expiresAt <= now) remoteIdleSessions.delete(key);
|
|
3881
|
+
}
|
|
3768
3882
|
}
|
|
3769
|
-
function
|
|
3770
|
-
|
|
3883
|
+
function getPendingEventsPath(meshId) {
|
|
3884
|
+
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
3885
|
+
return (0, import_path5.join)(getLedgerDir(), `${safe}.pending-events.jsonl`);
|
|
3771
3886
|
}
|
|
3772
|
-
function
|
|
3773
|
-
|
|
3887
|
+
function queuePendingMeshCoordinatorEvent(event) {
|
|
3888
|
+
try {
|
|
3889
|
+
(0, import_fs6.appendFileSync)(getPendingEventsPath(event.meshId), JSON.stringify(event) + "\n", "utf-8");
|
|
3890
|
+
return true;
|
|
3891
|
+
} catch (e) {
|
|
3892
|
+
LOG.warn("MeshEvents", `Failed to persist pending coordinator event: ${e?.message || e}`);
|
|
3893
|
+
return false;
|
|
3894
|
+
}
|
|
3895
|
+
}
|
|
3896
|
+
function drainPendingMeshCoordinatorEvents(meshId) {
|
|
3897
|
+
if (!meshId) return [];
|
|
3898
|
+
const path35 = getPendingEventsPath(meshId);
|
|
3899
|
+
if (!(0, import_fs6.existsSync)(path35)) return [];
|
|
3900
|
+
try {
|
|
3901
|
+
const raw = (0, import_fs6.readFileSync)(path35, "utf-8");
|
|
3902
|
+
try {
|
|
3903
|
+
(0, import_fs6.unlinkSync)(path35);
|
|
3904
|
+
} catch {
|
|
3905
|
+
}
|
|
3906
|
+
return raw.split("\n").filter(Boolean).flatMap((line) => {
|
|
3907
|
+
try {
|
|
3908
|
+
return [JSON.parse(line)];
|
|
3909
|
+
} catch {
|
|
3910
|
+
return [];
|
|
3911
|
+
}
|
|
3912
|
+
});
|
|
3913
|
+
} catch {
|
|
3914
|
+
return [];
|
|
3915
|
+
}
|
|
3916
|
+
}
|
|
3917
|
+
function getPendingMeshCoordinatorEvents(meshId) {
|
|
3918
|
+
if (!meshId) return [];
|
|
3919
|
+
const path35 = getPendingEventsPath(meshId);
|
|
3920
|
+
if (!(0, import_fs6.existsSync)(path35)) return [];
|
|
3921
|
+
try {
|
|
3922
|
+
const raw = (0, import_fs6.readFileSync)(path35, "utf-8");
|
|
3923
|
+
return raw.split("\n").filter(Boolean).flatMap((line) => {
|
|
3924
|
+
try {
|
|
3925
|
+
return [JSON.parse(line)];
|
|
3926
|
+
} catch {
|
|
3927
|
+
return [];
|
|
3928
|
+
}
|
|
3929
|
+
});
|
|
3930
|
+
} catch {
|
|
3931
|
+
return [];
|
|
3932
|
+
}
|
|
3933
|
+
}
|
|
3934
|
+
function clearPendingMeshCoordinatorEvents(meshId) {
|
|
3935
|
+
if (!meshId) return;
|
|
3936
|
+
const path35 = getPendingEventsPath(meshId);
|
|
3937
|
+
if ((0, import_fs6.existsSync)(path35)) try {
|
|
3938
|
+
(0, import_fs6.unlinkSync)(path35);
|
|
3939
|
+
} catch {
|
|
3940
|
+
}
|
|
3774
3941
|
}
|
|
3775
3942
|
function readNonEmptyString(value) {
|
|
3776
3943
|
return typeof value === "string" && value.trim() ? value.trim() : "";
|
|
@@ -3816,6 +3983,38 @@ function shouldSuppressIntentionalCleanupStop(args) {
|
|
|
3816
3983
|
if (isIntentionalCleanupStopMetadata(args.metadataEvent)) return true;
|
|
3817
3984
|
return hasRecentIntentionalCleanupStop(args.meshId, args.sessionId, args.nodeId);
|
|
3818
3985
|
}
|
|
3986
|
+
function readEventTimestamp(value) {
|
|
3987
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
3988
|
+
if (typeof value === "string" && value.trim()) {
|
|
3989
|
+
const numeric = Number(value);
|
|
3990
|
+
if (Number.isFinite(numeric)) return numeric;
|
|
3991
|
+
const parsed = Date.parse(value);
|
|
3992
|
+
if (Number.isFinite(parsed)) return parsed;
|
|
3993
|
+
}
|
|
3994
|
+
return null;
|
|
3995
|
+
}
|
|
3996
|
+
function buildMeshCompletionFingerprint(args) {
|
|
3997
|
+
const timestampPart = Number.isFinite(args.timestamp) ? String(args.timestamp) : readNonEmptyString(args.finalSummary).slice(0, 200);
|
|
3998
|
+
return [
|
|
3999
|
+
args.meshId,
|
|
4000
|
+
args.event,
|
|
4001
|
+
args.sessionId,
|
|
4002
|
+
args.providerType || "",
|
|
4003
|
+
args.providerSessionId || "",
|
|
4004
|
+
timestampPart
|
|
4005
|
+
].join("::");
|
|
4006
|
+
}
|
|
4007
|
+
function isDuplicateMeshCompletionEvent(args) {
|
|
4008
|
+
const fingerprint = buildMeshCompletionFingerprint(args);
|
|
4009
|
+
if (!fingerprint) return false;
|
|
4010
|
+
const now = Date.now();
|
|
4011
|
+
for (const [key, seenAt] of recentCompletionFingerprints.entries()) {
|
|
4012
|
+
if (now - seenAt > RECENT_COMPLETION_FINGERPRINT_TTL_MS) recentCompletionFingerprints.delete(key);
|
|
4013
|
+
}
|
|
4014
|
+
if (recentCompletionFingerprints.has(fingerprint)) return true;
|
|
4015
|
+
recentCompletionFingerprints.set(fingerprint, now);
|
|
4016
|
+
return false;
|
|
4017
|
+
}
|
|
3819
4018
|
function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType) {
|
|
3820
4019
|
const task = claimNextTask(meshId, nodeId, sessionId);
|
|
3821
4020
|
if (!task) {
|
|
@@ -3834,7 +4033,16 @@ function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType)
|
|
|
3834
4033
|
message: task.message
|
|
3835
4034
|
}).catch((e) => {
|
|
3836
4035
|
LOG.error("MeshQueue", `Failed to dispatch task via P2P to remote node ${nodeId}: ${e?.message}`);
|
|
3837
|
-
updateTaskStatus(meshId, task.id, "
|
|
4036
|
+
updateTaskStatus(meshId, task.id, "pending");
|
|
4037
|
+
try {
|
|
4038
|
+
appendLedgerEntry(meshId, {
|
|
4039
|
+
kind: "dispatch_failed",
|
|
4040
|
+
nodeId,
|
|
4041
|
+
sessionId,
|
|
4042
|
+
payload: { taskId: task.id, error: e?.message, retryable: true }
|
|
4043
|
+
});
|
|
4044
|
+
} catch {
|
|
4045
|
+
}
|
|
3838
4046
|
});
|
|
3839
4047
|
return true;
|
|
3840
4048
|
}
|
|
@@ -4168,18 +4376,36 @@ function injectMeshSystemMessage(components, args) {
|
|
|
4168
4376
|
LOG.info("MeshEvents", `Suppressed ${args.event} for intentionally cleanup-stopped session ${eventSessionId || "(unknown session)"}`);
|
|
4169
4377
|
return { success: true, forwarded: 0, suppressed: true, intentionalCleanupStop: true };
|
|
4170
4378
|
}
|
|
4379
|
+
const eventTimestamp = readEventTimestamp(args.metadataEvent.timestamp);
|
|
4380
|
+
if (args.event === "agent:generating_completed" && eventSessionId) {
|
|
4381
|
+
const duplicateCompletion = isDuplicateMeshCompletionEvent({
|
|
4382
|
+
meshId: args.meshId,
|
|
4383
|
+
event: args.event,
|
|
4384
|
+
sessionId: eventSessionId,
|
|
4385
|
+
providerType: readNonEmptyString(args.metadataEvent.providerType) || void 0,
|
|
4386
|
+
providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0,
|
|
4387
|
+
timestamp: eventTimestamp,
|
|
4388
|
+
finalSummary: readNonEmptyString(args.metadataEvent.finalSummary) || void 0
|
|
4389
|
+
});
|
|
4390
|
+
if (duplicateCompletion) {
|
|
4391
|
+
LOG.info("MeshEvents", `Suppressed duplicate completion for mesh ${args.meshId} session ${eventSessionId}`);
|
|
4392
|
+
return { success: true, forwarded: 0, suppressed: true, duplicateCompletion: true };
|
|
4393
|
+
}
|
|
4394
|
+
}
|
|
4171
4395
|
let completedTaskForLedger = null;
|
|
4172
4396
|
if (args.event === "agent:generating_completed") {
|
|
4173
4397
|
const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
|
|
4174
4398
|
const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
|
|
4175
4399
|
const providerType = readNonEmptyString(args.metadataEvent.providerType);
|
|
4176
4400
|
if (sessionId) {
|
|
4177
|
-
const completedTask = updateSessionTaskStatus(args.meshId, sessionId, "completed"
|
|
4401
|
+
const completedTask = updateSessionTaskStatus(args.meshId, sessionId, "completed", {
|
|
4402
|
+
occurredAt: eventTimestamp !== null ? new Date(eventTimestamp).toISOString() : void 0
|
|
4403
|
+
});
|
|
4178
4404
|
completedTaskForLedger = completedTask ? { id: completedTask.id } : null;
|
|
4179
4405
|
if (nodeId && providerType) {
|
|
4180
|
-
|
|
4406
|
+
setImmediate(() => {
|
|
4181
4407
|
tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
|
|
4182
|
-
}
|
|
4408
|
+
});
|
|
4183
4409
|
}
|
|
4184
4410
|
}
|
|
4185
4411
|
} else if (args.event === "agent:ready") {
|
|
@@ -4217,13 +4443,17 @@ function injectMeshSystemMessage(components, args) {
|
|
|
4217
4443
|
}
|
|
4218
4444
|
}
|
|
4219
4445
|
if (sessionId && nodeId && providerType) {
|
|
4220
|
-
|
|
4221
|
-
|
|
4446
|
+
sweepExpiredRemoteIdleSessions();
|
|
4447
|
+
remoteIdleSessions.set(`${nodeId}:${sessionId}`, {
|
|
4448
|
+
nodeId,
|
|
4449
|
+
sessionId,
|
|
4450
|
+
providerType,
|
|
4451
|
+
expiresAt: Date.now() + REMOTE_IDLE_SESSION_TTL_MS
|
|
4452
|
+
});
|
|
4453
|
+
setImmediate(() => {
|
|
4222
4454
|
const assigned = tryAssignQueueTask(components, args.meshId, nodeId, sessionId, providerType);
|
|
4223
|
-
if (assigned) {
|
|
4224
|
-
|
|
4225
|
-
}
|
|
4226
|
-
}, 500);
|
|
4455
|
+
if (assigned) remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
|
|
4456
|
+
});
|
|
4227
4457
|
}
|
|
4228
4458
|
} else if (args.event === "agent:generating_started") {
|
|
4229
4459
|
const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
|
|
@@ -4334,17 +4564,18 @@ function injectMeshSystemMessage(components, args) {
|
|
|
4334
4564
|
return true;
|
|
4335
4565
|
});
|
|
4336
4566
|
if (coordinatorInstances.length === 0) {
|
|
4337
|
-
if (
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
}
|
|
4346
|
-
|
|
4347
|
-
|
|
4567
|
+
if (queuePendingMeshCoordinatorEvent({
|
|
4568
|
+
event: args.event,
|
|
4569
|
+
meshId: args.meshId,
|
|
4570
|
+
nodeLabel: args.nodeLabel,
|
|
4571
|
+
nodeId: args.nodeId || void 0,
|
|
4572
|
+
workspace: readNonEmptyString(args.metadataEvent.workspace),
|
|
4573
|
+
metadataEvent: {
|
|
4574
|
+
...args.metadataEvent,
|
|
4575
|
+
...recoveryContext ? { recoveryContext } : {}
|
|
4576
|
+
},
|
|
4577
|
+
queuedAt: Date.now()
|
|
4578
|
+
})) {
|
|
4348
4579
|
LOG.info("MeshEvents", `Queued ${args.event} for MCP coordinator (mesh ${args.meshId})`);
|
|
4349
4580
|
}
|
|
4350
4581
|
return { success: true, forwarded: 0 };
|
|
@@ -4383,6 +4614,7 @@ function handleMeshForwardEvent(components, payload) {
|
|
|
4383
4614
|
providerType: readNonEmptyString(payload.providerType),
|
|
4384
4615
|
providerSessionId: readNonEmptyString(payload.providerSessionId),
|
|
4385
4616
|
finalSummary: readNonEmptyString(payload.finalSummary) || readNonEmptyString(payload.summary),
|
|
4617
|
+
...payload.timestamp !== void 0 ? { timestamp: payload.timestamp } : {},
|
|
4386
4618
|
intentional: payload.intentional === true,
|
|
4387
4619
|
intentionalStop: payload.intentionalStop === true,
|
|
4388
4620
|
operatorCleanup: payload.operatorCleanup === true,
|
|
@@ -4425,19 +4657,20 @@ function setupMeshEventForwarding(components) {
|
|
|
4425
4657
|
});
|
|
4426
4658
|
});
|
|
4427
4659
|
}
|
|
4428
|
-
var
|
|
4660
|
+
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;
|
|
4429
4661
|
var init_mesh_events = __esm({
|
|
4430
4662
|
"../../oss/packages/daemon-core/src/mesh/mesh-events.ts"() {
|
|
4431
4663
|
"use strict";
|
|
4664
|
+
import_fs6 = require("fs");
|
|
4665
|
+
import_path5 = require("path");
|
|
4432
4666
|
init_config();
|
|
4433
4667
|
init_mesh_config();
|
|
4434
4668
|
init_cli_detector();
|
|
4435
4669
|
init_logger();
|
|
4436
4670
|
init_mesh_ledger();
|
|
4437
4671
|
init_mesh_work_queue();
|
|
4672
|
+
REMOTE_IDLE_SESSION_TTL_MS = 5 * 60 * 1e3;
|
|
4438
4673
|
remoteIdleSessions = /* @__PURE__ */ new Map();
|
|
4439
|
-
MAX_PENDING_EVENTS = 50;
|
|
4440
|
-
pendingMeshCoordinatorEvents = [];
|
|
4441
4674
|
MESH_COORDINATOR_EVENTS = /* @__PURE__ */ new Set([
|
|
4442
4675
|
"agent:generating_started",
|
|
4443
4676
|
"agent:generating_completed",
|
|
@@ -4453,6 +4686,8 @@ var init_mesh_events = __esm({
|
|
|
4453
4686
|
"monitor:long_generating": "task_stalled"
|
|
4454
4687
|
};
|
|
4455
4688
|
INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS = 30 * 60 * 1e3;
|
|
4689
|
+
RECENT_COMPLETION_FINGERPRINT_TTL_MS = 10 * 60 * 1e3;
|
|
4690
|
+
recentCompletionFingerprints = /* @__PURE__ */ new Map();
|
|
4456
4691
|
autoLaunchInProgress = /* @__PURE__ */ new Set();
|
|
4457
4692
|
autoLaunchCooldownUntil = /* @__PURE__ */ new Map();
|
|
4458
4693
|
AUTO_LAUNCH_COOLDOWN_MS = 5e3;
|
|
@@ -4580,7 +4815,7 @@ function isPlainObject2(value) {
|
|
|
4580
4815
|
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
4581
4816
|
}
|
|
4582
4817
|
function getStatePath() {
|
|
4583
|
-
return (0,
|
|
4818
|
+
return (0, import_path6.join)(getConfigDir(), "state.json");
|
|
4584
4819
|
}
|
|
4585
4820
|
function normalizeState(raw) {
|
|
4586
4821
|
const parsed = isPlainObject2(raw) ? raw : {};
|
|
@@ -4616,11 +4851,11 @@ function normalizeState(raw) {
|
|
|
4616
4851
|
}
|
|
4617
4852
|
function loadState() {
|
|
4618
4853
|
const statePath = getStatePath();
|
|
4619
|
-
if (!(0,
|
|
4854
|
+
if (!(0, import_fs7.existsSync)(statePath)) {
|
|
4620
4855
|
return { ...DEFAULT_STATE };
|
|
4621
4856
|
}
|
|
4622
4857
|
try {
|
|
4623
|
-
const raw = (0,
|
|
4858
|
+
const raw = (0, import_fs7.readFileSync)(statePath, "utf-8");
|
|
4624
4859
|
return normalizeState(JSON.parse(raw));
|
|
4625
4860
|
} catch {
|
|
4626
4861
|
return { ...DEFAULT_STATE };
|
|
@@ -4629,17 +4864,17 @@ function loadState() {
|
|
|
4629
4864
|
function saveState(state) {
|
|
4630
4865
|
const statePath = getStatePath();
|
|
4631
4866
|
const normalized = normalizeState(state);
|
|
4632
|
-
(0,
|
|
4867
|
+
(0, import_fs7.writeFileSync)(statePath, JSON.stringify(normalized, null, 2), { encoding: "utf-8", mode: 384 });
|
|
4633
4868
|
}
|
|
4634
4869
|
function resetState() {
|
|
4635
4870
|
saveState({ ...DEFAULT_STATE });
|
|
4636
4871
|
}
|
|
4637
|
-
var
|
|
4872
|
+
var import_fs7, import_path6, DEFAULT_STATE;
|
|
4638
4873
|
var init_state_store = __esm({
|
|
4639
4874
|
"../../oss/packages/daemon-core/src/config/state-store.ts"() {
|
|
4640
4875
|
"use strict";
|
|
4641
|
-
|
|
4642
|
-
|
|
4876
|
+
import_fs7 = require("fs");
|
|
4877
|
+
import_path6 = require("path");
|
|
4643
4878
|
init_config();
|
|
4644
4879
|
DEFAULT_STATE = {
|
|
4645
4880
|
recentActivity: [],
|
|
@@ -4672,7 +4907,7 @@ function findCliCommand(command) {
|
|
|
4672
4907
|
if (path10.isAbsolute(trimmed) || trimmed.includes("/") || trimmed.includes("\\") || trimmed.startsWith("~")) {
|
|
4673
4908
|
const candidate = trimmed.startsWith("~") ? path10.join((0, import_os2.homedir)(), trimmed.slice(1)) : trimmed;
|
|
4674
4909
|
const resolved = path10.isAbsolute(candidate) ? candidate : path10.resolve(candidate);
|
|
4675
|
-
return (0,
|
|
4910
|
+
return (0, import_fs8.existsSync)(resolved) ? resolved : null;
|
|
4676
4911
|
}
|
|
4677
4912
|
try {
|
|
4678
4913
|
const result = (0, import_child_process2.execSync)(
|
|
@@ -4703,9 +4938,9 @@ function checkPathExists(paths) {
|
|
|
4703
4938
|
if (normalized.includes("*")) {
|
|
4704
4939
|
const username = home.split(/[\\/]/).pop() || "";
|
|
4705
4940
|
const resolved = normalized.replace("*", username);
|
|
4706
|
-
if ((0,
|
|
4941
|
+
if ((0, import_fs8.existsSync)(resolved)) return resolved;
|
|
4707
4942
|
} else {
|
|
4708
|
-
if ((0,
|
|
4943
|
+
if ((0, import_fs8.existsSync)(normalized)) return normalized;
|
|
4709
4944
|
}
|
|
4710
4945
|
}
|
|
4711
4946
|
return null;
|
|
@@ -4719,7 +4954,7 @@ async function detectIDEs(providerLoader) {
|
|
|
4719
4954
|
let resolvedCli = cliPath;
|
|
4720
4955
|
if (!resolvedCli && appPath && os30 === "darwin") {
|
|
4721
4956
|
const bundledCli = `${appPath}/Contents/Resources/app/bin/${def.cli}`;
|
|
4722
|
-
if ((0,
|
|
4957
|
+
if ((0, import_fs8.existsSync)(bundledCli)) resolvedCli = bundledCli;
|
|
4723
4958
|
}
|
|
4724
4959
|
if (!resolvedCli && appPath && os30 === "win32") {
|
|
4725
4960
|
const { dirname: dirname12 } = await import("path");
|
|
@@ -4732,7 +4967,7 @@ async function detectIDEs(providerLoader) {
|
|
|
4732
4967
|
`${appDir}\\\\resources\\\\app\\\\bin\\\\${def.cli}.cmd`
|
|
4733
4968
|
];
|
|
4734
4969
|
for (const c of candidates) {
|
|
4735
|
-
if ((0,
|
|
4970
|
+
if ((0, import_fs8.existsSync)(c)) {
|
|
4736
4971
|
resolvedCli = c;
|
|
4737
4972
|
break;
|
|
4738
4973
|
}
|
|
@@ -4753,12 +4988,12 @@ async function detectIDEs(providerLoader) {
|
|
|
4753
4988
|
}
|
|
4754
4989
|
return results;
|
|
4755
4990
|
}
|
|
4756
|
-
var import_child_process2,
|
|
4991
|
+
var import_child_process2, import_fs8, import_os2, path10, BUILTIN_IDE_DEFINITIONS, registeredIDEs;
|
|
4757
4992
|
var init_ide_detector = __esm({
|
|
4758
4993
|
"../../oss/packages/daemon-core/src/detection/ide-detector.ts"() {
|
|
4759
4994
|
"use strict";
|
|
4760
4995
|
import_child_process2 = require("child_process");
|
|
4761
|
-
|
|
4996
|
+
import_fs8 = require("fs");
|
|
4762
4997
|
import_os2 = require("os");
|
|
4763
4998
|
path10 = __toESM(require("path"));
|
|
4764
4999
|
BUILTIN_IDE_DEFINITIONS = [];
|
|
@@ -6679,7 +6914,7 @@ var init_status_monitor = __esm({
|
|
|
6679
6914
|
});
|
|
6680
6915
|
|
|
6681
6916
|
// ../../oss/packages/daemon-core/src/providers/chat-message-normalization.ts
|
|
6682
|
-
function extractFinalSummaryFromMessages(messages, maxChars =
|
|
6917
|
+
function extractFinalSummaryFromMessages(messages, maxChars = DEFAULT_FINAL_SUMMARY_MAX_CHARS) {
|
|
6683
6918
|
if (!Array.isArray(messages) || messages.length === 0) return "";
|
|
6684
6919
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
6685
6920
|
const msg = messages[i];
|
|
@@ -6981,11 +7216,12 @@ function filterInternalChatMessages(messages) {
|
|
|
6981
7216
|
function filterChatMessagesByVisibility(messages, surface) {
|
|
6982
7217
|
return (Array.isArray(messages) ? messages : []).filter((message) => classifyChatMessageVisibility(message).surface === surface);
|
|
6983
7218
|
}
|
|
6984
|
-
var BUILTIN_CHAT_MESSAGE_KINDS, CHAT_MESSAGE_VISIBILITIES, CHAT_MESSAGE_TRANSCRIPT_VISIBILITIES, CHAT_MESSAGE_AUDIENCES, CHAT_MESSAGE_SOURCES, CHAT_MESSAGE_ACTIVITY_SOURCES, CHAT_MESSAGE_INTERNAL_SOURCES, KNOWN_CHAT_MESSAGE_KINDS, CHAT_MESSAGE_KIND_ALIASES, EXPLICIT_HIDDEN_VISIBILITIES, EXPLICIT_VISIBLE_VISIBILITIES, HIDDEN_AUDIENCES, ACTIVITY_SOURCE_SET, INTERNAL_SOURCE_SET;
|
|
7219
|
+
var DEFAULT_FINAL_SUMMARY_MAX_CHARS, BUILTIN_CHAT_MESSAGE_KINDS, CHAT_MESSAGE_VISIBILITIES, CHAT_MESSAGE_TRANSCRIPT_VISIBILITIES, CHAT_MESSAGE_AUDIENCES, CHAT_MESSAGE_SOURCES, CHAT_MESSAGE_ACTIVITY_SOURCES, CHAT_MESSAGE_INTERNAL_SOURCES, KNOWN_CHAT_MESSAGE_KINDS, CHAT_MESSAGE_KIND_ALIASES, EXPLICIT_HIDDEN_VISIBILITIES, EXPLICIT_VISIBLE_VISIBILITIES, HIDDEN_AUDIENCES, ACTIVITY_SOURCE_SET, INTERNAL_SOURCE_SET;
|
|
6985
7220
|
var init_chat_message_normalization = __esm({
|
|
6986
7221
|
"../../oss/packages/daemon-core/src/providers/chat-message-normalization.ts"() {
|
|
6987
7222
|
"use strict";
|
|
6988
7223
|
init_contracts();
|
|
7224
|
+
DEFAULT_FINAL_SUMMARY_MAX_CHARS = 4e3;
|
|
6989
7225
|
BUILTIN_CHAT_MESSAGE_KINDS = ["standard", "thought", "tool", "terminal", "system"];
|
|
6990
7226
|
CHAT_MESSAGE_VISIBILITIES = ["user", "debug", "internal", "hidden"];
|
|
6991
7227
|
CHAT_MESSAGE_TRANSCRIPT_VISIBILITIES = ["visible", "chat", "user", "debug", "internal", "hidden"];
|
|
@@ -36737,7 +36973,7 @@ function commandExists(command) {
|
|
|
36737
36973
|
const trimmed = command.trim();
|
|
36738
36974
|
if (!trimmed) return false;
|
|
36739
36975
|
if (isExplicitCommand(trimmed)) {
|
|
36740
|
-
return (0,
|
|
36976
|
+
return (0, import_fs9.existsSync)(expandExecutable(trimmed));
|
|
36741
36977
|
}
|
|
36742
36978
|
try {
|
|
36743
36979
|
(0, import_child_process6.execFileSync)(process.platform === "win32" ? "where" : "which", [trimmed], {
|
|
@@ -36758,10 +36994,10 @@ function hasCliArg(args, flag) {
|
|
|
36758
36994
|
}
|
|
36759
36995
|
function ensureEmptyDelegatedMcpConfig(workspace) {
|
|
36760
36996
|
const baseDir = path18.join(os15.tmpdir(), "adhdev-delegated-agent-empty-mcp");
|
|
36761
|
-
(0,
|
|
36997
|
+
(0, import_fs9.mkdirSync)(baseDir, { recursive: true });
|
|
36762
36998
|
const workspaceHash = crypto4.createHash("sha256").update(path18.resolve(workspace || os15.tmpdir())).digest("hex").slice(0, 16);
|
|
36763
36999
|
const filePath = path18.join(baseDir, `${workspaceHash}.json`);
|
|
36764
|
-
(0,
|
|
37000
|
+
(0, import_fs9.writeFileSync)(filePath, JSON.stringify({ mcpServers: {} }, null, 2), "utf-8");
|
|
36765
37001
|
return filePath;
|
|
36766
37002
|
}
|
|
36767
37003
|
function buildCoordinatorDelegatedCliLaunchOptions(input) {
|
|
@@ -36888,14 +37124,14 @@ function resolveCliSessionBinding(provider, normalizedType, cliArgs, requestedRe
|
|
|
36888
37124
|
launchMode: "new"
|
|
36889
37125
|
};
|
|
36890
37126
|
}
|
|
36891
|
-
var os15, path18, crypto4,
|
|
37127
|
+
var os15, path18, crypto4, import_fs9, import_child_process6, chalkModule, chalkApi, COORDINATOR_DELEGATED_ENV_UNSETS, DaemonCliManager;
|
|
36892
37128
|
var init_cli_manager = __esm({
|
|
36893
37129
|
"../../oss/packages/daemon-core/src/commands/cli-manager.ts"() {
|
|
36894
37130
|
"use strict";
|
|
36895
37131
|
os15 = __toESM(require("os"));
|
|
36896
37132
|
path18 = __toESM(require("path"));
|
|
36897
37133
|
crypto4 = __toESM(require("crypto"));
|
|
36898
|
-
|
|
37134
|
+
import_fs9 = require("fs");
|
|
36899
37135
|
import_child_process6 = require("child_process");
|
|
36900
37136
|
init_source();
|
|
36901
37137
|
init_provider_cli_adapter();
|
|
@@ -37809,7 +38045,7 @@ function createFsWatchInstance(path35, options, listener, errHandler, emitRaw) {
|
|
|
37809
38045
|
}
|
|
37810
38046
|
};
|
|
37811
38047
|
try {
|
|
37812
|
-
return (0,
|
|
38048
|
+
return (0, import_fs10.watch)(path35, {
|
|
37813
38049
|
persistent: options.persistent
|
|
37814
38050
|
}, handleEvent);
|
|
37815
38051
|
} catch (error48) {
|
|
@@ -37817,11 +38053,11 @@ function createFsWatchInstance(path35, options, listener, errHandler, emitRaw) {
|
|
|
37817
38053
|
return void 0;
|
|
37818
38054
|
}
|
|
37819
38055
|
}
|
|
37820
|
-
var
|
|
38056
|
+
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;
|
|
37821
38057
|
var init_handler2 = __esm({
|
|
37822
38058
|
"../../oss/node_modules/chokidar/esm/handler.js"() {
|
|
37823
38059
|
"use strict";
|
|
37824
|
-
|
|
38060
|
+
import_fs10 = require("fs");
|
|
37825
38061
|
import_promises5 = require("fs/promises");
|
|
37826
38062
|
sysPath = __toESM(require("path"), 1);
|
|
37827
38063
|
import_os3 = require("os");
|
|
@@ -38225,7 +38461,7 @@ var init_handler2 = __esm({
|
|
|
38225
38461
|
let cont = FsWatchFileInstances.get(fullPath);
|
|
38226
38462
|
const copts = cont && cont.options;
|
|
38227
38463
|
if (copts && (copts.persistent < options.persistent || copts.interval > options.interval)) {
|
|
38228
|
-
(0,
|
|
38464
|
+
(0, import_fs10.unwatchFile)(fullPath);
|
|
38229
38465
|
cont = void 0;
|
|
38230
38466
|
}
|
|
38231
38467
|
if (cont) {
|
|
@@ -38236,7 +38472,7 @@ var init_handler2 = __esm({
|
|
|
38236
38472
|
listeners: listener,
|
|
38237
38473
|
rawEmitters: rawEmitter,
|
|
38238
38474
|
options,
|
|
38239
|
-
watcher: (0,
|
|
38475
|
+
watcher: (0, import_fs10.watchFile)(fullPath, options, (curr, prev) => {
|
|
38240
38476
|
foreach(cont.rawEmitters, (rawEmitter2) => {
|
|
38241
38477
|
rawEmitter2(EV.CHANGE, fullPath, { curr, prev });
|
|
38242
38478
|
});
|
|
@@ -38253,7 +38489,7 @@ var init_handler2 = __esm({
|
|
|
38253
38489
|
delFromSet(cont, KEY_RAW, rawEmitter);
|
|
38254
38490
|
if (isEmptySet(cont.listeners)) {
|
|
38255
38491
|
FsWatchFileInstances.delete(fullPath);
|
|
38256
|
-
(0,
|
|
38492
|
+
(0, import_fs10.unwatchFile)(fullPath);
|
|
38257
38493
|
cont.options = cont.watcher = void 0;
|
|
38258
38494
|
Object.freeze(cont);
|
|
38259
38495
|
}
|
|
@@ -38631,11 +38867,11 @@ function watch(paths, options = {}) {
|
|
|
38631
38867
|
watcher.add(paths);
|
|
38632
38868
|
return watcher;
|
|
38633
38869
|
}
|
|
38634
|
-
var
|
|
38870
|
+
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;
|
|
38635
38871
|
var init_esm2 = __esm({
|
|
38636
38872
|
"../../oss/node_modules/chokidar/esm/index.js"() {
|
|
38637
38873
|
"use strict";
|
|
38638
|
-
|
|
38874
|
+
import_fs11 = require("fs");
|
|
38639
38875
|
import_promises6 = require("fs/promises");
|
|
38640
38876
|
import_events2 = require("events");
|
|
38641
38877
|
sysPath2 = __toESM(require("path"), 1);
|
|
@@ -39113,7 +39349,7 @@ var init_esm2 = __esm({
|
|
|
39113
39349
|
const now = /* @__PURE__ */ new Date();
|
|
39114
39350
|
const writes = this._pendingWrites;
|
|
39115
39351
|
function awaitWriteFinishFn(prevStat) {
|
|
39116
|
-
(0,
|
|
39352
|
+
(0, import_fs11.stat)(fullPath, (err, curStat) => {
|
|
39117
39353
|
if (err || !writes.has(path35)) {
|
|
39118
39354
|
if (err && err.code !== "ENOENT")
|
|
39119
39355
|
awfEmit(err);
|
|
@@ -45414,52 +45650,33 @@ function readBooleanValue(...values) {
|
|
|
45414
45650
|
}
|
|
45415
45651
|
return void 0;
|
|
45416
45652
|
}
|
|
45417
|
-
function
|
|
45418
|
-
|
|
45419
|
-
const
|
|
45420
|
-
|
|
45421
|
-
const
|
|
45422
|
-
const
|
|
45423
|
-
const
|
|
45424
|
-
|
|
45425
|
-
|
|
45426
|
-
|
|
45427
|
-
|
|
45428
|
-
|
|
45429
|
-
|
|
45430
|
-
|
|
45431
|
-
|
|
45432
|
-
|
|
45433
|
-
|
|
45434
|
-
|
|
45435
|
-
|
|
45436
|
-
|
|
45437
|
-
|
|
45438
|
-
untracked: readNumberValue(cachedGit.untracked) ?? 0,
|
|
45439
|
-
deleted: readNumberValue(cachedGit.deleted) ?? 0,
|
|
45440
|
-
renamed: readNumberValue(cachedGit.renamed) ?? 0,
|
|
45441
|
-
hasConflicts: hasConflicts2,
|
|
45442
|
-
conflictFiles: conflictFiles2,
|
|
45443
|
-
stashCount: readNumberValue(cachedGit.stashCount) ?? 0,
|
|
45444
|
-
lastCheckedAt: readNumberValue(cachedGit.lastCheckedAt) ?? Date.now()
|
|
45445
|
-
};
|
|
45446
|
-
}
|
|
45447
|
-
}
|
|
45448
|
-
const rawGit = readObjectRecord(node?.lastGit ?? node?.last_git);
|
|
45449
|
-
const gitResult = readObjectRecord(rawGit.result);
|
|
45450
|
-
const directStatus = readObjectRecord(rawGit.status);
|
|
45451
|
-
const nestedStatus = readObjectRecord(gitResult.status);
|
|
45452
|
-
const rawProbe = readObjectRecord(node?.lastProbe ?? node?.last_probe);
|
|
45453
|
-
const probeGit = readObjectRecord(rawProbe.git);
|
|
45454
|
-
const probeGitResult = readObjectRecord(probeGit.result);
|
|
45455
|
-
const probeDirectStatus = readObjectRecord(probeGit.status);
|
|
45456
|
-
const probeNestedStatus = readObjectRecord(probeGitResult.status);
|
|
45457
|
-
const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
|
|
45653
|
+
function readGitSubmodules(value) {
|
|
45654
|
+
if (!Array.isArray(value)) return void 0;
|
|
45655
|
+
const submodules = value.map((entry) => {
|
|
45656
|
+
const submodule = readObjectRecord(entry);
|
|
45657
|
+
const path35 = readStringValue(submodule.path);
|
|
45658
|
+
const commit = readStringValue(submodule.commit);
|
|
45659
|
+
const repoPath = readStringValue(submodule.repoPath, submodule.repo_root);
|
|
45660
|
+
if (!path35 || !commit || !repoPath) return null;
|
|
45661
|
+
return {
|
|
45662
|
+
path: path35,
|
|
45663
|
+
commit,
|
|
45664
|
+
repoPath,
|
|
45665
|
+
dirty: readBooleanValue(submodule.dirty) ?? false,
|
|
45666
|
+
outOfSync: readBooleanValue(submodule.outOfSync, submodule.out_of_sync) ?? false,
|
|
45667
|
+
lastCheckedAt: readNumberValue(submodule.lastCheckedAt, submodule.last_checked_at) ?? Date.now(),
|
|
45668
|
+
...readStringValue(submodule.error) ? { error: readStringValue(submodule.error) } : {}
|
|
45669
|
+
};
|
|
45670
|
+
}).filter((entry) => entry !== null);
|
|
45671
|
+
return submodules.length > 0 ? submodules : void 0;
|
|
45672
|
+
}
|
|
45673
|
+
function normalizeInlineMeshGitStatus(status, node, options) {
|
|
45458
45674
|
const isGitRepo = readBooleanValue(status.isGitRepo);
|
|
45459
45675
|
if (!Object.keys(status).length || isGitRepo === void 0) return void 0;
|
|
45460
45676
|
const conflictFiles = Array.isArray(status.conflictFiles) ? status.conflictFiles.filter((value) => typeof value === "string") : [];
|
|
45461
45677
|
const conflictCount = readNumberValue(status.conflicts) ?? conflictFiles.length;
|
|
45462
45678
|
const hasConflicts = readBooleanValue(status.hasConflicts) ?? conflictCount > 0;
|
|
45679
|
+
const submodules = readGitSubmodules(status.submodules);
|
|
45463
45680
|
return {
|
|
45464
45681
|
workspace: readStringValue(status.workspace, node?.workspace) || "",
|
|
45465
45682
|
repoRoot: readStringValue(status.repoRoot, node?.repoRoot, node?.workspace) || null,
|
|
@@ -45478,29 +45695,285 @@ function buildCachedInlineMeshGitStatus(node) {
|
|
|
45478
45695
|
hasConflicts,
|
|
45479
45696
|
conflictFiles,
|
|
45480
45697
|
stashCount: readNumberValue(status.stashCount) ?? 0,
|
|
45481
|
-
lastCheckedAt: Date.now()
|
|
45698
|
+
lastCheckedAt: options?.lastCheckedAt ?? readNumberValue(status.lastCheckedAt) ?? Date.now(),
|
|
45699
|
+
...submodules ? { submodules } : {}
|
|
45482
45700
|
};
|
|
45483
45701
|
}
|
|
45484
|
-
function
|
|
45702
|
+
function buildInlineMeshTransitGitStatus(node) {
|
|
45703
|
+
const rawGit = readObjectRecord(node?.lastGit ?? node?.last_git);
|
|
45704
|
+
const gitResult = readObjectRecord(rawGit.result);
|
|
45705
|
+
const directStatus = readObjectRecord(rawGit.status);
|
|
45706
|
+
const nestedStatus = readObjectRecord(gitResult.status);
|
|
45707
|
+
const rawProbe = readObjectRecord(node?.lastProbe ?? node?.last_probe);
|
|
45708
|
+
const probeGit = readObjectRecord(rawProbe.git);
|
|
45709
|
+
const probeGitResult = readObjectRecord(probeGit.result);
|
|
45710
|
+
const probeDirectStatus = readObjectRecord(probeGit.status);
|
|
45711
|
+
const probeNestedStatus = readObjectRecord(probeGitResult.status);
|
|
45712
|
+
const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
|
|
45713
|
+
return normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
|
|
45714
|
+
}
|
|
45715
|
+
function buildCachedInlineMeshGitStatus(node) {
|
|
45716
|
+
const liveGit = buildInlineMeshTransitGitStatus(node);
|
|
45717
|
+
if (liveGit) return liveGit;
|
|
45718
|
+
const cachedStatus = readObjectRecord(node?.cachedStatus);
|
|
45719
|
+
const cachedGit = readObjectRecord(cachedStatus.git);
|
|
45720
|
+
if (!Object.keys(cachedGit).length) return void 0;
|
|
45721
|
+
return normalizeInlineMeshGitStatus(cachedGit, node);
|
|
45722
|
+
}
|
|
45723
|
+
function shouldDiscardCachedInlineMeshStatus(node) {
|
|
45724
|
+
const cachedStatus = readObjectRecord(node?.cachedStatus);
|
|
45725
|
+
if (!Object.keys(cachedStatus).length) return false;
|
|
45726
|
+
const cachedGit = readObjectRecord(cachedStatus.git);
|
|
45727
|
+
const workspaceError = readStringValue(cachedStatus.error, node?.error);
|
|
45728
|
+
if (workspaceError && /workspace must be an existing directory/i.test(workspaceError)) return true;
|
|
45729
|
+
const isGitRepo = readBooleanValue(cachedGit.isGitRepo);
|
|
45730
|
+
const branch = readStringValue(cachedGit.branch);
|
|
45731
|
+
const headCommit = readStringValue(cachedGit.headCommit);
|
|
45732
|
+
return isGitRepo === false && !branch && !headCommit;
|
|
45733
|
+
}
|
|
45734
|
+
function stripInlineMeshTransientNodeState(node) {
|
|
45735
|
+
if (!node || typeof node !== "object" || Array.isArray(node)) return node;
|
|
45736
|
+
const {
|
|
45737
|
+
cachedStatus,
|
|
45738
|
+
lastGit: _lastGit,
|
|
45739
|
+
last_git: _lastGitLegacy,
|
|
45740
|
+
lastProbe: _lastProbe,
|
|
45741
|
+
last_probe: _lastProbeLegacy,
|
|
45742
|
+
error: _error,
|
|
45743
|
+
health: _health,
|
|
45744
|
+
machineStatus: _machineStatus,
|
|
45745
|
+
lastSeenAt: _lastSeenAt,
|
|
45746
|
+
last_seen_at: _lastSeenAtLegacy,
|
|
45747
|
+
updatedAt: _updatedAt,
|
|
45748
|
+
updated_at: _updatedAtLegacy,
|
|
45749
|
+
activeSession: _activeSession,
|
|
45750
|
+
active_session: _activeSessionLegacy,
|
|
45751
|
+
activeSessionId: _activeSessionId,
|
|
45752
|
+
active_session_id: _activeSessionIdLegacy,
|
|
45753
|
+
sessionId: _sessionId,
|
|
45754
|
+
session_id: _sessionIdLegacy,
|
|
45755
|
+
providerType: _providerType,
|
|
45756
|
+
provider_type: _providerTypeLegacy,
|
|
45757
|
+
providers: _providers,
|
|
45758
|
+
...rest
|
|
45759
|
+
} = node;
|
|
45760
|
+
if (cachedStatus && !shouldDiscardCachedInlineMeshStatus(node)) {
|
|
45761
|
+
return { ...rest, cachedStatus };
|
|
45762
|
+
}
|
|
45763
|
+
return rest;
|
|
45764
|
+
}
|
|
45765
|
+
function hasInlineMeshTransientNodeState(node) {
|
|
45766
|
+
if (!node || typeof node !== "object" || Array.isArray(node)) return false;
|
|
45767
|
+
return "cachedStatus" in node || "lastGit" in node || "last_git" in node || "lastProbe" in node || "last_probe" in node || "error" in node || "health" in node || "machineStatus" in node || "lastSeenAt" in node || "last_seen_at" in node || "updatedAt" in node || "updated_at" in node || "activeSession" in node || "active_session" in node || "activeSessionId" in node || "active_session_id" in node || "sessionId" in node || "session_id" in node || "providerType" in node || "provider_type" in node || "providers" in node;
|
|
45768
|
+
}
|
|
45769
|
+
function readInlineMeshNodeId(node) {
|
|
45770
|
+
return readStringValue(node?.id, node?.nodeId) || "";
|
|
45771
|
+
}
|
|
45772
|
+
function sanitizeInlineMesh(inlineMesh) {
|
|
45773
|
+
if (!inlineMesh || typeof inlineMesh !== "object" || Array.isArray(inlineMesh)) return inlineMesh;
|
|
45774
|
+
if (!Array.isArray(inlineMesh.nodes)) return inlineMesh;
|
|
45775
|
+
let changed = false;
|
|
45776
|
+
const nodes = inlineMesh.nodes.map((node) => {
|
|
45777
|
+
if (!hasInlineMeshTransientNodeState(node)) return node;
|
|
45778
|
+
changed = true;
|
|
45779
|
+
return stripInlineMeshTransientNodeState(node);
|
|
45780
|
+
});
|
|
45781
|
+
if (!changed) return inlineMesh;
|
|
45782
|
+
return {
|
|
45783
|
+
...inlineMesh,
|
|
45784
|
+
nodes
|
|
45785
|
+
};
|
|
45786
|
+
}
|
|
45787
|
+
function reconcileInlineMeshCache(cached2, incoming) {
|
|
45788
|
+
if (!cached2 || typeof cached2 !== "object" || Array.isArray(cached2)) return incoming;
|
|
45789
|
+
if (!incoming || typeof incoming !== "object" || Array.isArray(incoming)) return cached2;
|
|
45790
|
+
const cachedNodes = Array.isArray(cached2.nodes) ? cached2.nodes : [];
|
|
45791
|
+
const incomingNodes = Array.isArray(incoming.nodes) ? incoming.nodes : [];
|
|
45792
|
+
if (!cachedNodes.length || !incomingNodes.length) return { ...cached2, ...incoming };
|
|
45793
|
+
const incomingById = /* @__PURE__ */ new Map();
|
|
45794
|
+
for (const node of incomingNodes) {
|
|
45795
|
+
const nodeId = readInlineMeshNodeId(node);
|
|
45796
|
+
if (nodeId) incomingById.set(nodeId, node);
|
|
45797
|
+
}
|
|
45798
|
+
const nodes = cachedNodes.map((cachedNode) => {
|
|
45799
|
+
const nodeId = readInlineMeshNodeId(cachedNode);
|
|
45800
|
+
const incomingNode = nodeId ? incomingById.get(nodeId) : void 0;
|
|
45801
|
+
if (!incomingNode) return cachedNode;
|
|
45802
|
+
if (hasInlineMeshTransientNodeState(incomingNode)) {
|
|
45803
|
+
return { ...cachedNode, ...incomingNode };
|
|
45804
|
+
}
|
|
45805
|
+
return { ...stripInlineMeshTransientNodeState(cachedNode), ...incomingNode };
|
|
45806
|
+
});
|
|
45807
|
+
return {
|
|
45808
|
+
...cached2,
|
|
45809
|
+
...incoming,
|
|
45810
|
+
nodes
|
|
45811
|
+
};
|
|
45812
|
+
}
|
|
45813
|
+
function hasGitWorktreeChanges(git) {
|
|
45814
|
+
if (!git) return false;
|
|
45815
|
+
return Number(git.staged || 0) + Number(git.modified || 0) + Number(git.untracked || 0) + Number(git.deleted || 0) + Number(git.renamed || 0) > 0;
|
|
45816
|
+
}
|
|
45817
|
+
function getGitSubmoduleDriftState(git) {
|
|
45818
|
+
const submodules = Array.isArray(git?.submodules) ? git.submodules : [];
|
|
45819
|
+
let dirty = false;
|
|
45820
|
+
let outOfSync = false;
|
|
45821
|
+
for (const entry of submodules) {
|
|
45822
|
+
const submodule = readObjectRecord(entry);
|
|
45823
|
+
if (readBooleanValue(submodule.dirty) === true) dirty = true;
|
|
45824
|
+
if (readBooleanValue(submodule.outOfSync) === true || !!readStringValue(submodule.error)) outOfSync = true;
|
|
45825
|
+
}
|
|
45826
|
+
return { dirty, outOfSync };
|
|
45827
|
+
}
|
|
45828
|
+
function deriveMeshNodeHealthFromGit(git) {
|
|
45829
|
+
if (!git || readBooleanValue(git.isGitRepo) === false) return "degraded";
|
|
45830
|
+
const branch = readStringValue(git.branch);
|
|
45831
|
+
if (!branch) return "degraded";
|
|
45832
|
+
const submoduleDrift = getGitSubmoduleDriftState(git);
|
|
45833
|
+
if (submoduleDrift.outOfSync) return "degraded";
|
|
45834
|
+
if (submoduleDrift.dirty || hasGitWorktreeChanges(git)) return "dirty";
|
|
45835
|
+
return "online";
|
|
45836
|
+
}
|
|
45837
|
+
function readCachedInlineMeshActiveSessions(node) {
|
|
45838
|
+
const cachedStatus = readObjectRecord(node?.cachedStatus);
|
|
45839
|
+
const activeSession = readObjectRecord(cachedStatus.activeSession);
|
|
45840
|
+
const fallbackSession = Object.keys(activeSession).length ? activeSession : readObjectRecord(node?.activeSession ?? node?.active_session);
|
|
45841
|
+
const sessionId = readStringValue(fallbackSession.id, fallbackSession.sessionId, fallbackSession.session_id, node?.activeSessionId, node?.active_session_id, node?.sessionId, node?.session_id);
|
|
45842
|
+
return sessionId ? [sessionId] : [];
|
|
45843
|
+
}
|
|
45844
|
+
function readCachedInlineMeshActiveSessionDetails(node) {
|
|
45845
|
+
const cachedStatus = readObjectRecord(node?.cachedStatus);
|
|
45846
|
+
const activeSession = readObjectRecord(cachedStatus.activeSession);
|
|
45847
|
+
const fallbackSession = Object.keys(activeSession).length ? activeSession : readObjectRecord(node?.activeSession ?? node?.active_session);
|
|
45848
|
+
const sessionId = readStringValue(
|
|
45849
|
+
fallbackSession.id,
|
|
45850
|
+
fallbackSession.sessionId,
|
|
45851
|
+
fallbackSession.session_id,
|
|
45852
|
+
node?.activeSessionId,
|
|
45853
|
+
node?.active_session_id,
|
|
45854
|
+
node?.sessionId,
|
|
45855
|
+
node?.session_id
|
|
45856
|
+
);
|
|
45857
|
+
if (!sessionId) return [];
|
|
45858
|
+
return [{
|
|
45859
|
+
sessionId,
|
|
45860
|
+
providerType: readStringValue(
|
|
45861
|
+
fallbackSession.providerType,
|
|
45862
|
+
fallbackSession.provider_type,
|
|
45863
|
+
fallbackSession.cliType,
|
|
45864
|
+
fallbackSession.cli_type,
|
|
45865
|
+
fallbackSession.provider,
|
|
45866
|
+
node?.providerType,
|
|
45867
|
+
node?.provider_type
|
|
45868
|
+
),
|
|
45869
|
+
state: readStringValue(fallbackSession.status, fallbackSession.state, fallbackSession.lifecycle),
|
|
45870
|
+
lifecycle: readStringValue(fallbackSession.lifecycle),
|
|
45871
|
+
title: readStringValue(fallbackSession.title, fallbackSession.displayName, fallbackSession.display_name) ?? null,
|
|
45872
|
+
workspace: readStringValue(fallbackSession.workspace, node?.workspace) ?? null,
|
|
45873
|
+
lastActivityAt: readStringValue(fallbackSession.lastActivityAt, fallbackSession.last_activity_at) ?? null,
|
|
45874
|
+
recoveryState: readStringValue(fallbackSession.recoveryState, fallbackSession.recovery_state) ?? null,
|
|
45875
|
+
isCached: true
|
|
45876
|
+
}];
|
|
45877
|
+
}
|
|
45878
|
+
function readLiveMeshSessionState(record2) {
|
|
45879
|
+
return readStringValue(
|
|
45880
|
+
record2?.meta?.sessionStatus,
|
|
45881
|
+
record2?.meta?.status,
|
|
45882
|
+
record2?.meta?.providerStatus,
|
|
45883
|
+
record2?.status,
|
|
45884
|
+
record2?.state,
|
|
45885
|
+
record2?.lifecycle
|
|
45886
|
+
);
|
|
45887
|
+
}
|
|
45888
|
+
function toIsoTimestamp(value) {
|
|
45889
|
+
if (typeof value === "number" && Number.isFinite(value)) return new Date(value).toISOString();
|
|
45890
|
+
const stringValue = readStringValue(value);
|
|
45891
|
+
return stringValue || null;
|
|
45892
|
+
}
|
|
45893
|
+
function summarizeMeshSessionRecord(record2) {
|
|
45894
|
+
return {
|
|
45895
|
+
sessionId: readStringValue(record2?.sessionId) || "unknown",
|
|
45896
|
+
providerType: readStringValue(record2?.providerType),
|
|
45897
|
+
state: readLiveMeshSessionState(record2),
|
|
45898
|
+
lifecycle: readStringValue(record2?.lifecycle),
|
|
45899
|
+
surfaceKind: getSessionHostSurfaceKind(record2),
|
|
45900
|
+
recoveryState: readStringValue(record2?.meta?.runtimeRecoveryState) ?? null,
|
|
45901
|
+
workspace: readStringValue(record2?.workspace) ?? null,
|
|
45902
|
+
title: readStringValue(record2?.displayName, record2?.workspaceLabel) ?? null,
|
|
45903
|
+
lastActivityAt: toIsoTimestamp(record2?.updatedAt ?? record2?.lastActivityAt ?? record2?.last_activity_at),
|
|
45904
|
+
isCached: false
|
|
45905
|
+
};
|
|
45906
|
+
}
|
|
45907
|
+
function liveSessionRecordMatchesMeshNode(record2, meshId, nodeId) {
|
|
45908
|
+
const recordNodeId = readStringValue(record2?.meta?.meshNodeId);
|
|
45909
|
+
if (!recordNodeId || recordNodeId !== nodeId) return false;
|
|
45910
|
+
const recordMeshId = readStringValue(record2?.meta?.meshNodeFor);
|
|
45911
|
+
return !recordMeshId || recordMeshId === meshId;
|
|
45912
|
+
}
|
|
45913
|
+
function liveSessionRecordMatchesMeshWorkspace(record2, meshId, workspace) {
|
|
45914
|
+
const recordWorkspace = readStringValue(record2?.workspace);
|
|
45915
|
+
if (!recordWorkspace || !workspace || recordWorkspace !== workspace) return false;
|
|
45916
|
+
const recordMeshId = readStringValue(record2?.meta?.meshNodeFor);
|
|
45917
|
+
if (recordMeshId) return recordMeshId === meshId;
|
|
45918
|
+
return record2?.meta?.launchedByCoordinator === true || !!readStringValue(record2?.meta?.meshNodeId);
|
|
45919
|
+
}
|
|
45920
|
+
function readLiveMeshNodeWorkspace(args) {
|
|
45921
|
+
const directNodeWorkspace = args.liveSessionRecords.find((record2) => liveSessionRecordMatchesMeshNode(record2, args.meshId, args.nodeId) && readStringValue(record2?.workspace));
|
|
45922
|
+
if (directNodeWorkspace) {
|
|
45923
|
+
return readStringValue(directNodeWorkspace.workspace) || "";
|
|
45924
|
+
}
|
|
45925
|
+
if (args.allowCoordinatorSession) {
|
|
45926
|
+
const coordinatorWorkspace = args.liveSessionRecords.find((record2) => readStringValue(record2?.meta?.meshCoordinatorFor) === args.meshId && readStringValue(record2?.workspace));
|
|
45927
|
+
if (coordinatorWorkspace) {
|
|
45928
|
+
return readStringValue(coordinatorWorkspace.workspace) || "";
|
|
45929
|
+
}
|
|
45930
|
+
}
|
|
45931
|
+
return "";
|
|
45932
|
+
}
|
|
45933
|
+
function collectLiveMeshSessionRecords(args) {
|
|
45934
|
+
const matches = args.liveSessionRecords.filter((record2) => {
|
|
45935
|
+
const nodeWorkspace = readStringValue(args.node?.workspace);
|
|
45936
|
+
if (liveSessionRecordMatchesMeshNode(record2, args.meshId, args.nodeId)) return true;
|
|
45937
|
+
return !!nodeWorkspace && liveSessionRecordMatchesMeshWorkspace(record2, args.meshId, nodeWorkspace);
|
|
45938
|
+
});
|
|
45939
|
+
if (args.allowCoordinatorSession) {
|
|
45940
|
+
for (const record2 of args.liveSessionRecords) {
|
|
45941
|
+
if (readStringValue(record2?.meta?.meshCoordinatorFor) !== args.meshId) continue;
|
|
45942
|
+
const sessionId = readStringValue(record2?.sessionId);
|
|
45943
|
+
if (sessionId && matches.some((entry) => readStringValue(entry?.sessionId) === sessionId)) continue;
|
|
45944
|
+
matches.push(record2);
|
|
45945
|
+
}
|
|
45946
|
+
}
|
|
45947
|
+
return matches;
|
|
45948
|
+
}
|
|
45949
|
+
function applyCachedInlineMeshNodeStatus(status, node, options) {
|
|
45485
45950
|
const cachedStatus = readObjectRecord(node?.cachedStatus);
|
|
45486
|
-
const
|
|
45487
|
-
const
|
|
45488
|
-
const
|
|
45951
|
+
const liveGit = buildInlineMeshTransitGitStatus(node);
|
|
45952
|
+
const git = options?.skipGit ? void 0 : liveGit ?? buildCachedInlineMeshGitStatus(node);
|
|
45953
|
+
const error48 = options?.skipError ? void 0 : liveGit ? void 0 : readStringValue(cachedStatus.error, node?.error);
|
|
45954
|
+
const health = options?.skipHealth ? void 0 : liveGit ? void 0 : readStringValue(cachedStatus.health, node?.health);
|
|
45489
45955
|
const machineStatus = readStringValue(cachedStatus.machineStatus, node?.machineStatus);
|
|
45490
|
-
|
|
45491
|
-
|
|
45956
|
+
const lastSeenAt = toIsoTimestamp(cachedStatus.lastSeenAt ?? cachedStatus.last_seen_at ?? node?.lastSeenAt ?? node?.last_seen_at);
|
|
45957
|
+
const updatedAt = toIsoTimestamp(cachedStatus.updatedAt ?? cachedStatus.updated_at ?? node?.updatedAt ?? node?.updated_at);
|
|
45958
|
+
const activeSessions = readCachedInlineMeshActiveSessions(node);
|
|
45959
|
+
const activeSessionDetails = readCachedInlineMeshActiveSessionDetails(node);
|
|
45960
|
+
if (!git && !error48 && !health && !machineStatus && !lastSeenAt && !updatedAt && activeSessions.length === 0) return false;
|
|
45492
45961
|
if (git) status.git = git;
|
|
45493
45962
|
if (error48) status.error = error48;
|
|
45963
|
+
if (machineStatus) status.machineStatus = machineStatus;
|
|
45964
|
+
if (lastSeenAt) status.lastSeenAt = lastSeenAt;
|
|
45965
|
+
if (updatedAt) status.updatedAt = updatedAt;
|
|
45966
|
+
if (activeSessions.length > 0) status.activeSessions = activeSessions;
|
|
45967
|
+
if (activeSessionDetails.length > 0) status.activeSessionDetails = activeSessionDetails;
|
|
45494
45968
|
if (health) {
|
|
45495
45969
|
status.health = health;
|
|
45496
45970
|
return true;
|
|
45497
45971
|
}
|
|
45498
45972
|
if (git) {
|
|
45499
|
-
|
|
45500
|
-
status.health = git.isGitRepo === false ? "degraded" : dirty ? "dirty" : "online";
|
|
45973
|
+
status.health = deriveMeshNodeHealthFromGit(git);
|
|
45501
45974
|
return true;
|
|
45502
45975
|
}
|
|
45503
|
-
return
|
|
45976
|
+
return activeSessions.length > 0 || !!machineStatus || !!lastSeenAt || !!updatedAt;
|
|
45504
45977
|
}
|
|
45505
45978
|
async function resolveProviderTypeFromPriority(args) {
|
|
45506
45979
|
if (!args.providerPriority.length) {
|
|
@@ -45533,7 +46006,7 @@ function truncateValidationOutput(value) {
|
|
|
45533
46006
|
}
|
|
45534
46007
|
function readPackageScripts(workspace) {
|
|
45535
46008
|
try {
|
|
45536
|
-
const packageJsonPath = (0,
|
|
46009
|
+
const packageJsonPath = (0, import_path7.join)(workspace, "package.json");
|
|
45537
46010
|
const parsed = JSON.parse(fs10.readFileSync(packageJsonPath, "utf-8"));
|
|
45538
46011
|
return parsed?.scripts && typeof parsed.scripts === "object" && !Array.isArray(parsed.scripts) ? parsed.scripts : {};
|
|
45539
46012
|
} catch {
|
|
@@ -45741,13 +46214,13 @@ function serializeMeshCoordinatorMcpConfig(config2, format) {
|
|
|
45741
46214
|
}
|
|
45742
46215
|
function resolveHermesUserHome() {
|
|
45743
46216
|
const explicitHome = process.env.HERMES_HOME?.trim();
|
|
45744
|
-
return explicitHome || (0,
|
|
46217
|
+
return explicitHome || (0, import_path7.join)((0, import_os4.homedir)(), ".hermes");
|
|
45745
46218
|
}
|
|
45746
46219
|
function loadHermesCoordinatorBaseConfig(targetConfigPath) {
|
|
45747
46220
|
const sourceHome = resolveHermesUserHome();
|
|
45748
|
-
const sourceConfigPath = (0,
|
|
46221
|
+
const sourceConfigPath = (0, import_path7.join)(sourceHome, "config.yaml");
|
|
45749
46222
|
if (!fs10.existsSync(sourceConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
45750
|
-
if ((0,
|
|
46223
|
+
if ((0, import_path7.resolve)(sourceConfigPath) === (0, import_path7.resolve)(targetConfigPath)) return { config: {}, sourceHome, sourceConfigPath };
|
|
45751
46224
|
const parsed = parseMeshCoordinatorMcpConfig(fs10.readFileSync(sourceConfigPath, "utf-8"), "hermes_config_yaml");
|
|
45752
46225
|
const { mcp_servers: _mcpServers, ...baseConfig } = parsed;
|
|
45753
46226
|
return { config: baseConfig, sourceHome, sourceConfigPath };
|
|
@@ -45781,10 +46254,10 @@ function stripHermesCoordinatorTempModelProviderOverrides(config2) {
|
|
|
45781
46254
|
return sanitized;
|
|
45782
46255
|
}
|
|
45783
46256
|
function copyHermesCoordinatorCredentialFiles(sourceHome, targetHome) {
|
|
45784
|
-
if ((0,
|
|
46257
|
+
if ((0, import_path7.resolve)(sourceHome) === (0, import_path7.resolve)(targetHome)) return;
|
|
45785
46258
|
for (const fileName of [".env", "auth.json"]) {
|
|
45786
|
-
const sourcePath = (0,
|
|
45787
|
-
const targetPath = (0,
|
|
46259
|
+
const sourcePath = (0, import_path7.join)(sourceHome, fileName);
|
|
46260
|
+
const targetPath = (0, import_path7.join)(targetHome, fileName);
|
|
45788
46261
|
if (!fs10.existsSync(sourcePath)) continue;
|
|
45789
46262
|
try {
|
|
45790
46263
|
fs10.copyFileSync(sourcePath, targetPath);
|
|
@@ -45874,7 +46347,7 @@ function summarizeSessionHostPruneResult(result) {
|
|
|
45874
46347
|
keptCount: Array.isArray(value.keptSessionIds) ? value.keptSessionIds.length : void 0
|
|
45875
46348
|
};
|
|
45876
46349
|
}
|
|
45877
|
-
var import_os4,
|
|
46350
|
+
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;
|
|
45878
46351
|
var init_router = __esm({
|
|
45879
46352
|
"../../oss/packages/daemon-core/src/commands/router.ts"() {
|
|
45880
46353
|
"use strict";
|
|
@@ -45890,6 +46363,7 @@ var init_router = __esm({
|
|
|
45890
46363
|
init_chat_history();
|
|
45891
46364
|
init_ide_detector();
|
|
45892
46365
|
init_cli_detector();
|
|
46366
|
+
init_git_status();
|
|
45893
46367
|
init_logger();
|
|
45894
46368
|
init_command_log();
|
|
45895
46369
|
init_js_yaml();
|
|
@@ -45903,7 +46377,7 @@ var init_router = __esm({
|
|
|
45903
46377
|
init_snapshot();
|
|
45904
46378
|
init_upgrade_helper();
|
|
45905
46379
|
import_os4 = require("os");
|
|
45906
|
-
|
|
46380
|
+
import_path7 = require("path");
|
|
45907
46381
|
fs10 = __toESM(require("fs"));
|
|
45908
46382
|
CHANNEL_NPM_TAG = { stable: "latest", preview: "next" };
|
|
45909
46383
|
CHANNEL_SERVER_URL = {
|
|
@@ -45934,25 +46408,40 @@ var init_router = __esm({
|
|
|
45934
46408
|
}
|
|
45935
46409
|
getCachedInlineMesh(meshId, inlineMesh) {
|
|
45936
46410
|
if (inlineMesh && typeof inlineMesh === "object") {
|
|
45937
|
-
this.
|
|
45938
|
-
return inlineMesh;
|
|
46411
|
+
return this.warmInlineMeshCache(meshId, inlineMesh);
|
|
45939
46412
|
}
|
|
45940
46413
|
return this.inlineMeshCache.get(meshId);
|
|
45941
46414
|
}
|
|
46415
|
+
warmInlineMeshCache(meshId, inlineMesh) {
|
|
46416
|
+
if (!inlineMesh || typeof inlineMesh !== "object") return void 0;
|
|
46417
|
+
const sanitizedInlineMesh = sanitizeInlineMesh(inlineMesh);
|
|
46418
|
+
const cached2 = this.inlineMeshCache.get(meshId);
|
|
46419
|
+
if (cached2) {
|
|
46420
|
+
const merged = reconcileInlineMeshCache(cached2, sanitizedInlineMesh);
|
|
46421
|
+
this.inlineMeshCache.set(meshId, merged);
|
|
46422
|
+
return merged;
|
|
46423
|
+
}
|
|
46424
|
+
this.inlineMeshCache.set(meshId, sanitizedInlineMesh);
|
|
46425
|
+
return sanitizedInlineMesh;
|
|
46426
|
+
}
|
|
45942
46427
|
async getMeshForCommand(meshId, inlineMesh, options) {
|
|
45943
46428
|
const preferInline = options?.preferInline === true;
|
|
45944
46429
|
if (preferInline) {
|
|
45945
|
-
const cached3 = this.getCachedInlineMesh(meshId
|
|
45946
|
-
if (cached3) return { mesh: cached3, inline: true };
|
|
46430
|
+
const cached3 = this.getCachedInlineMesh(meshId);
|
|
46431
|
+
if (cached3) return { mesh: cached3, inline: true, source: "inline_cache" };
|
|
46432
|
+
const warmedInline2 = this.warmInlineMeshCache(meshId, inlineMesh);
|
|
46433
|
+
if (warmedInline2) return { mesh: warmedInline2, inline: true, source: "inline_bootstrap" };
|
|
45947
46434
|
}
|
|
45948
46435
|
try {
|
|
45949
46436
|
const { getMesh: getMesh3 } = await Promise.resolve().then(() => (init_mesh_config(), mesh_config_exports));
|
|
45950
46437
|
const mesh = getMesh3(meshId);
|
|
45951
|
-
if (mesh) return { mesh, inline: false };
|
|
46438
|
+
if (mesh) return { mesh, inline: false, source: "local_config" };
|
|
45952
46439
|
} catch {
|
|
45953
46440
|
}
|
|
45954
|
-
const cached2 = this.getCachedInlineMesh(meshId
|
|
45955
|
-
|
|
46441
|
+
const cached2 = this.getCachedInlineMesh(meshId);
|
|
46442
|
+
if (cached2) return { mesh: cached2, inline: true, source: "inline_cache" };
|
|
46443
|
+
const warmedInline = this.warmInlineMeshCache(meshId, inlineMesh);
|
|
46444
|
+
return warmedInline ? { mesh: warmedInline, inline: true, source: "inline_bootstrap" } : null;
|
|
45956
46445
|
}
|
|
45957
46446
|
updateInlineMeshNode(meshId, mesh, node) {
|
|
45958
46447
|
if (!mesh || !Array.isArray(mesh.nodes) || !node?.id) return;
|
|
@@ -46017,7 +46506,7 @@ var init_router = __esm({
|
|
|
46017
46506
|
}
|
|
46018
46507
|
const { resolveWorktreePath: resolveWorktreePath2, listWorktrees: listWorktrees2, removeWorktree: removeWorktree2 } = await Promise.resolve().then(() => (init_git_worktree(), git_worktree_exports));
|
|
46019
46508
|
const normalizePath2 = (value) => {
|
|
46020
|
-
const resolved = (0,
|
|
46509
|
+
const resolved = (0, import_path7.resolve)(value);
|
|
46021
46510
|
try {
|
|
46022
46511
|
return fs10.realpathSync(resolved);
|
|
46023
46512
|
} catch {
|
|
@@ -46181,6 +46670,7 @@ var init_router = __esm({
|
|
|
46181
46670
|
const deletedSessionIds = [];
|
|
46182
46671
|
const skippedSessionIds = [];
|
|
46183
46672
|
const skippedLiveSessionIds = [];
|
|
46673
|
+
const skippedCoordinatorSessionIds = [];
|
|
46184
46674
|
const deleteUnsupportedSessionIds = [];
|
|
46185
46675
|
const recordsRemainSessionIds = [];
|
|
46186
46676
|
const errors = [];
|
|
@@ -46213,6 +46703,12 @@ var init_router = __esm({
|
|
|
46213
46703
|
const completed = this.isCompletedHostedSession(record2);
|
|
46214
46704
|
const surfaceKind = getSessionHostSurfaceKind(record2);
|
|
46215
46705
|
const liveRuntime = surfaceKind === "live_runtime";
|
|
46706
|
+
const coordinatorSession = readStringValue(record2?.meta?.meshCoordinatorFor) === args.meshId;
|
|
46707
|
+
if (!hasExplicitSessionIds && coordinatorSession) {
|
|
46708
|
+
skippedSessionIds.push(sessionId);
|
|
46709
|
+
skippedCoordinatorSessionIds.push(sessionId);
|
|
46710
|
+
continue;
|
|
46711
|
+
}
|
|
46216
46712
|
if (!hasExplicitSessionIds && liveRuntime) {
|
|
46217
46713
|
skippedSessionIds.push(sessionId);
|
|
46218
46714
|
skippedLiveSessionIds.push(sessionId);
|
|
@@ -46278,6 +46774,7 @@ var init_router = __esm({
|
|
|
46278
46774
|
deletedSessionIds,
|
|
46279
46775
|
skippedSessionIds,
|
|
46280
46776
|
skippedLiveSessionIds,
|
|
46777
|
+
skippedCoordinatorSessionIds,
|
|
46281
46778
|
...deleteUnsupported ? {
|
|
46282
46779
|
deleteUnsupported: true,
|
|
46283
46780
|
effectiveCleanup: args.mode === "stop_and_delete" ? "stopped_only_records_remain" : "delete_unsupported_records_remain",
|
|
@@ -46410,7 +46907,8 @@ var init_router = __esm({
|
|
|
46410
46907
|
return handleMeshForwardEvent({ instanceManager: this.deps.instanceManager }, args);
|
|
46411
46908
|
}
|
|
46412
46909
|
case "get_pending_mesh_events": {
|
|
46413
|
-
const
|
|
46910
|
+
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46911
|
+
const events = drainPendingMeshCoordinatorEvents(meshId || void 0);
|
|
46414
46912
|
return { success: true, events };
|
|
46415
46913
|
}
|
|
46416
46914
|
case "launch_cli":
|
|
@@ -46939,14 +47437,8 @@ var init_router = __esm({
|
|
|
46939
47437
|
case "get_mesh": {
|
|
46940
47438
|
const meshId = typeof args?.meshId === "string" ? args.meshId.trim() : "";
|
|
46941
47439
|
if (!meshId) return { success: false, error: "meshId required" };
|
|
46942
|
-
|
|
46943
|
-
|
|
46944
|
-
const mesh = getMesh3(meshId);
|
|
46945
|
-
if (mesh) return { success: true, mesh };
|
|
46946
|
-
} catch {
|
|
46947
|
-
}
|
|
46948
|
-
const cached2 = this.inlineMeshCache.get(meshId);
|
|
46949
|
-
if (cached2) return { success: true, mesh: cached2 };
|
|
47440
|
+
const meshRecord = await this.getMeshForCommand(meshId, args?.inlineMesh, { preferInline: true });
|
|
47441
|
+
if (meshRecord?.mesh) return { success: true, mesh: meshRecord.mesh };
|
|
46950
47442
|
return { success: false, error: "Mesh not found" };
|
|
46951
47443
|
}
|
|
46952
47444
|
case "create_mesh": {
|
|
@@ -47468,7 +47960,14 @@ var init_router = __esm({
|
|
|
47468
47960
|
cliType
|
|
47469
47961
|
};
|
|
47470
47962
|
}
|
|
47471
|
-
const
|
|
47963
|
+
const sessionHostRecords = this.deps.sessionHostControl?.listSessions ? await this.deps.sessionHostControl.listSessions().catch(() => []) : [];
|
|
47964
|
+
const liveMeshSessions = partitionSessionHostRecords(Array.isArray(sessionHostRecords) ? sessionHostRecords : []).liveRuntimes;
|
|
47965
|
+
const workspace = readLiveMeshNodeWorkspace({
|
|
47966
|
+
meshId,
|
|
47967
|
+
nodeId: String(coordinatorNode.id || coordinatorNode.nodeId || preferredCoordinatorNodeId || ""),
|
|
47968
|
+
liveSessionRecords: liveMeshSessions,
|
|
47969
|
+
allowCoordinatorSession: true
|
|
47970
|
+
}) || (typeof coordinatorNode.workspace === "string" ? coordinatorNode.workspace.trim() : "");
|
|
47472
47971
|
if (!workspace) return { success: false, error: "Coordinator node workspace required", meshId, cliType };
|
|
47473
47972
|
if (!cliType) {
|
|
47474
47973
|
const resolved = await resolveProviderTypeFromPriority({
|
|
@@ -47630,7 +48129,7 @@ ${block}`);
|
|
|
47630
48129
|
workspace
|
|
47631
48130
|
};
|
|
47632
48131
|
}
|
|
47633
|
-
const { existsSync:
|
|
48132
|
+
const { existsSync: existsSync30, readFileSync: readFileSync23, writeFileSync: writeFileSync17, copyFileSync: copyFileSync5, mkdirSync: mkdirSync21 } = await import("fs");
|
|
47634
48133
|
const { dirname: dirname12 } = await import("path");
|
|
47635
48134
|
const mcpConfigPath = coordinatorSetup.configPath;
|
|
47636
48135
|
const hermesManualFallback = cliType === "hermes-cli" && configFormat === "hermes_config_yaml" ? createHermesManualMeshCoordinatorSetup(meshId, workspace) : null;
|
|
@@ -47673,14 +48172,14 @@ ${block}`);
|
|
|
47673
48172
|
if (hermesManualFallback) return returnManualFallback(message);
|
|
47674
48173
|
return { success: false, code: "mesh_coordinator_config_write_failed", error: message, meshId, cliType, workspace };
|
|
47675
48174
|
}
|
|
47676
|
-
const hadExistingMcpConfig =
|
|
48175
|
+
const hadExistingMcpConfig = existsSync30(mcpConfigPath);
|
|
47677
48176
|
let existingMcpConfig = hermesBaseConfig?.config || {};
|
|
47678
48177
|
if (hermesBaseConfig) {
|
|
47679
48178
|
copyHermesCoordinatorCredentialFiles(hermesBaseConfig.sourceHome, dirname12(mcpConfigPath));
|
|
47680
48179
|
}
|
|
47681
48180
|
if (hadExistingMcpConfig) {
|
|
47682
48181
|
try {
|
|
47683
|
-
const parsedExistingMcpConfig = parseMeshCoordinatorMcpConfig(
|
|
48182
|
+
const parsedExistingMcpConfig = parseMeshCoordinatorMcpConfig(readFileSync23(mcpConfigPath, "utf-8"), configFormat);
|
|
47684
48183
|
const existingCoordinatorConfig = hermesManualFallback ? stripHermesCoordinatorTempModelProviderOverrides(parsedExistingMcpConfig) : parsedExistingMcpConfig;
|
|
47685
48184
|
existingMcpConfig = { ...existingMcpConfig, ...existingCoordinatorConfig };
|
|
47686
48185
|
copyFileSync5(mcpConfigPath, mcpConfigPath + ".backup");
|
|
@@ -47776,92 +48275,157 @@ ${block}`);
|
|
|
47776
48275
|
const { readLedgerEntries: readLedgerEntries2, getLedgerSummary: getLedgerSummary2 } = await Promise.resolve().then(() => (init_mesh_ledger(), mesh_ledger_exports));
|
|
47777
48276
|
const ledgerEntries = readLedgerEntries2(meshId, { tail: 20 });
|
|
47778
48277
|
const ledgerSummary = getLedgerSummary2(meshId);
|
|
48278
|
+
const sessionHostRecords = this.deps.sessionHostControl?.listSessions ? await this.deps.sessionHostControl.listSessions().catch(() => []) : [];
|
|
48279
|
+
const liveMeshSessions = partitionSessionHostRecords(Array.isArray(sessionHostRecords) ? sessionHostRecords : []).liveRuntimes;
|
|
48280
|
+
const localMachineId = loadConfig().machineId || "";
|
|
48281
|
+
const selectedCoordinatorNodeId = readStringValue(
|
|
48282
|
+
mesh.coordinator?.preferredNodeId,
|
|
48283
|
+
mesh.nodes?.[0]?.id,
|
|
48284
|
+
mesh.nodes?.[0]?.nodeId
|
|
48285
|
+
);
|
|
48286
|
+
const inlineCoordinatorNodeId = meshRecord?.inline && Array.isArray(mesh.nodes) ? selectedCoordinatorNodeId : void 0;
|
|
48287
|
+
const refreshedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
47779
48288
|
const nodeStatuses = [];
|
|
47780
|
-
for (const node of mesh.nodes || []) {
|
|
48289
|
+
for (const [nodeIndex, node] of (mesh.nodes || []).entries()) {
|
|
48290
|
+
const nodeId = String(node.id || node.nodeId || "");
|
|
48291
|
+
const daemonId = readStringValue(node.daemonId);
|
|
48292
|
+
const providerPriority = readProviderPriorityFromPolicy(node.policy);
|
|
48293
|
+
const isSelfNode = Boolean(
|
|
48294
|
+
nodeId && inlineCoordinatorNodeId && nodeId === inlineCoordinatorNodeId
|
|
48295
|
+
) || Boolean(
|
|
48296
|
+
daemonId && (daemonId === localMachineId || daemonId === this.deps.statusInstanceId)
|
|
48297
|
+
) || Boolean(meshRecord?.inline && nodeIndex === 0);
|
|
47781
48298
|
const status = {
|
|
47782
|
-
nodeId
|
|
48299
|
+
nodeId,
|
|
47783
48300
|
machineLabel: node.machineLabel || node.id || node.nodeId,
|
|
47784
48301
|
workspace: node.workspace,
|
|
47785
48302
|
repoRoot: node.repoRoot,
|
|
47786
48303
|
isLocalWorktree: node.isLocalWorktree,
|
|
47787
48304
|
worktreeBranch: node.worktreeBranch,
|
|
47788
|
-
daemonId
|
|
48305
|
+
daemonId,
|
|
47789
48306
|
machineId: node.machineId,
|
|
48307
|
+
machineStatus: node.machineStatus,
|
|
47790
48308
|
health: "unknown",
|
|
47791
48309
|
providers: node.providers || [],
|
|
47792
|
-
|
|
48310
|
+
providerPriority,
|
|
48311
|
+
activeSessions: [],
|
|
48312
|
+
activeSessionDetails: [],
|
|
48313
|
+
launchReady: false
|
|
47793
48314
|
};
|
|
47794
|
-
if (
|
|
47795
|
-
|
|
47796
|
-
|
|
47797
|
-
|
|
48315
|
+
if (isSelfNode) {
|
|
48316
|
+
status.connection = {
|
|
48317
|
+
perspective: "selected_coordinator",
|
|
48318
|
+
source: "mesh_peer_status",
|
|
48319
|
+
state: "self",
|
|
48320
|
+
transport: "local",
|
|
48321
|
+
reported: true,
|
|
48322
|
+
reason: "Selected coordinator daemon",
|
|
48323
|
+
lastStateChangeAt: refreshedAt
|
|
48324
|
+
};
|
|
48325
|
+
} else if (daemonId) {
|
|
48326
|
+
const connection = this.deps.getMeshPeerConnectionStatus?.(daemonId);
|
|
48327
|
+
status.connection = connection ?? {
|
|
48328
|
+
perspective: "selected_coordinator",
|
|
48329
|
+
source: "not_reported",
|
|
48330
|
+
state: "unknown",
|
|
48331
|
+
transport: "unknown",
|
|
48332
|
+
reported: false,
|
|
48333
|
+
reason: "No live mesh peer telemetry reported by the selected coordinator yet."
|
|
48334
|
+
};
|
|
48335
|
+
} else {
|
|
48336
|
+
status.connection = {
|
|
48337
|
+
perspective: "selected_coordinator",
|
|
48338
|
+
source: "not_reported",
|
|
48339
|
+
state: "unknown",
|
|
48340
|
+
transport: "unknown",
|
|
48341
|
+
reported: false,
|
|
48342
|
+
reason: "Node has no daemon id, so mesh transport cannot be reported from the selected coordinator."
|
|
48343
|
+
};
|
|
48344
|
+
}
|
|
48345
|
+
const matchedLiveSessionRecords = collectLiveMeshSessionRecords({
|
|
48346
|
+
meshId,
|
|
48347
|
+
node,
|
|
48348
|
+
nodeId,
|
|
48349
|
+
liveSessionRecords: liveMeshSessions,
|
|
48350
|
+
allowCoordinatorSession: nodeId === selectedCoordinatorNodeId
|
|
48351
|
+
});
|
|
48352
|
+
const workspace = readLiveMeshNodeWorkspace({
|
|
48353
|
+
meshId,
|
|
48354
|
+
nodeId,
|
|
48355
|
+
liveSessionRecords: matchedLiveSessionRecords,
|
|
48356
|
+
allowCoordinatorSession: nodeId === selectedCoordinatorNodeId
|
|
48357
|
+
}) || (typeof node.workspace === "string" ? node.workspace : "");
|
|
48358
|
+
status.workspace = workspace || node.workspace;
|
|
48359
|
+
if (matchedLiveSessionRecords.length > 0) {
|
|
48360
|
+
const sessionIds = matchedLiveSessionRecords.map((record2) => typeof record2?.sessionId === "string" ? record2.sessionId : "").filter(Boolean);
|
|
48361
|
+
const providerTypes = matchedLiveSessionRecords.map((record2) => readStringValue(record2?.providerType)).filter(Boolean);
|
|
48362
|
+
status.activeSessions = sessionIds;
|
|
48363
|
+
status.activeSessionDetails = matchedLiveSessionRecords.map(summarizeMeshSessionRecord);
|
|
48364
|
+
if (providerTypes.length > 0) {
|
|
48365
|
+
status.providers = Array.from(/* @__PURE__ */ new Set([...Array.isArray(status.providers) ? status.providers : [], ...providerTypes]));
|
|
47798
48366
|
}
|
|
47799
|
-
|
|
47800
|
-
|
|
47801
|
-
|
|
47802
|
-
|
|
47803
|
-
|
|
47804
|
-
|
|
47805
|
-
|
|
47806
|
-
|
|
47807
|
-
|
|
47808
|
-
|
|
47809
|
-
|
|
47810
|
-
|
|
47811
|
-
|
|
47812
|
-
|
|
47813
|
-
|
|
47814
|
-
|
|
47815
|
-
|
|
47816
|
-
const stashCount = await runGit2(["stash", "list"]).catch(() => "");
|
|
47817
|
-
let ahead = 0, behind = 0;
|
|
47818
|
-
if (aheadBehind) {
|
|
47819
|
-
const parts = aheadBehind.split(/\s+/);
|
|
47820
|
-
if (parts.length >= 2) {
|
|
47821
|
-
behind = parseInt(parts[0], 10) || 0;
|
|
47822
|
-
ahead = parseInt(parts[1], 10) || 0;
|
|
48367
|
+
}
|
|
48368
|
+
if (workspace) {
|
|
48369
|
+
if (!fs10.existsSync(workspace)) {
|
|
48370
|
+
let remoteProbeApplied = false;
|
|
48371
|
+
if (!isSelfNode && daemonId && this.deps.dispatchMeshCommand) {
|
|
48372
|
+
try {
|
|
48373
|
+
const remoteResult = await Promise.race([
|
|
48374
|
+
this.deps.dispatchMeshCommand(daemonId, "git_status", { workspace }),
|
|
48375
|
+
new Promise((_2, reject) => setTimeout(() => reject(new Error("timeout")), 8e3))
|
|
48376
|
+
]);
|
|
48377
|
+
const remoteGit = remoteResult?.status ?? remoteResult?.git ?? remoteResult;
|
|
48378
|
+
if (remoteGit && typeof remoteGit === "object" && typeof remoteGit.isGitRepo === "boolean") {
|
|
48379
|
+
status.git = remoteGit;
|
|
48380
|
+
status.health = remoteGit.isGitRepo ? deriveMeshNodeHealthFromGit(remoteGit) : "degraded";
|
|
48381
|
+
remoteProbeApplied = true;
|
|
48382
|
+
}
|
|
48383
|
+
} catch {
|
|
47823
48384
|
}
|
|
47824
48385
|
}
|
|
47825
|
-
|
|
47826
|
-
|
|
47827
|
-
|
|
47828
|
-
|
|
47829
|
-
|
|
47830
|
-
|
|
47831
|
-
|
|
47832
|
-
|
|
47833
|
-
if (
|
|
47834
|
-
|
|
48386
|
+
if (!remoteProbeApplied) {
|
|
48387
|
+
const connectionState = readStringValue(status.connection?.state);
|
|
48388
|
+
const inlineTransitGit = buildInlineMeshTransitGitStatus(node);
|
|
48389
|
+
const pendingPeerGitProbe = !inlineTransitGit && !isSelfNode && !!daemonId && (readStringValue(status.machineStatus) === "online" || readStringValue(status.health) === "online" || connectionState === "connecting" || connectionState === "connected" || connectionState === "unknown");
|
|
48390
|
+
if (pendingPeerGitProbe) {
|
|
48391
|
+
status.gitProbePending = true;
|
|
48392
|
+
status.health = "unknown";
|
|
48393
|
+
}
|
|
48394
|
+
if (applyCachedInlineMeshNodeStatus(
|
|
48395
|
+
status,
|
|
48396
|
+
node,
|
|
48397
|
+
pendingPeerGitProbe ? { skipGit: true, skipError: true, skipHealth: true } : void 0
|
|
48398
|
+
)) {
|
|
48399
|
+
status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
|
|
48400
|
+
nodeStatuses.push(status);
|
|
48401
|
+
continue;
|
|
48402
|
+
}
|
|
48403
|
+
if (meshRecord?.source === "inline_cache" && !isSelfNode) {
|
|
48404
|
+
status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
|
|
48405
|
+
nodeStatuses.push(status);
|
|
48406
|
+
continue;
|
|
48407
|
+
}
|
|
47835
48408
|
}
|
|
47836
|
-
|
|
47837
|
-
|
|
47838
|
-
|
|
47839
|
-
|
|
47840
|
-
|
|
47841
|
-
|
|
47842
|
-
|
|
47843
|
-
|
|
47844
|
-
|
|
47845
|
-
|
|
47846
|
-
|
|
47847
|
-
|
|
47848
|
-
|
|
47849
|
-
|
|
47850
|
-
renamed: renamed2,
|
|
47851
|
-
hasConflicts: false,
|
|
47852
|
-
conflictFiles: [],
|
|
47853
|
-
stashCount: stashCount ? stashCount.split("\n").filter(Boolean).length : 0,
|
|
47854
|
-
lastCheckedAt: Date.now()
|
|
47855
|
-
};
|
|
47856
|
-
status.health = branch ? dirty ? "dirty" : "online" : "degraded";
|
|
47857
|
-
} catch {
|
|
47858
|
-
if (!applyCachedInlineMeshNodeStatus(status, node)) {
|
|
47859
|
-
status.health = "degraded";
|
|
48409
|
+
} else {
|
|
48410
|
+
try {
|
|
48411
|
+
const gitStatus = await getGitRepoStatus(workspace, { timeoutMs: 1e4, refreshUpstream: true });
|
|
48412
|
+
status.git = gitStatus;
|
|
48413
|
+
if (gitStatus.isGitRepo) {
|
|
48414
|
+
status.health = deriveMeshNodeHealthFromGit(gitStatus);
|
|
48415
|
+
} else {
|
|
48416
|
+
status.health = "degraded";
|
|
48417
|
+
if (gitStatus.error && !status.error) status.error = gitStatus.error;
|
|
48418
|
+
}
|
|
48419
|
+
} catch {
|
|
48420
|
+
if (!applyCachedInlineMeshNodeStatus(status, node)) {
|
|
48421
|
+
status.health = "degraded";
|
|
48422
|
+
}
|
|
47860
48423
|
}
|
|
47861
48424
|
}
|
|
47862
48425
|
} else {
|
|
47863
48426
|
applyCachedInlineMeshNodeStatus(status, node);
|
|
47864
48427
|
}
|
|
48428
|
+
status.launchReady = !!daemonId && (readStringValue(status.machineStatus) === "online" || isSelfNode);
|
|
47865
48429
|
nodeStatuses.push(status);
|
|
47866
48430
|
}
|
|
47867
48431
|
return {
|
|
@@ -47870,6 +48434,12 @@ ${block}`);
|
|
|
47870
48434
|
meshName: mesh.name,
|
|
47871
48435
|
repoIdentity: mesh.repoIdentity,
|
|
47872
48436
|
defaultBranch: mesh.defaultBranch,
|
|
48437
|
+
refreshedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
48438
|
+
sourceOfTruth: {
|
|
48439
|
+
membership: meshRecord?.source === "inline_cache" ? "coordinator_inline_mesh_cache" : meshRecord?.source === "local_config" ? "local_mesh_config" : "inline_bootstrap_snapshot",
|
|
48440
|
+
coordinatorOwnsLiveTruth: meshRecord?.source !== "inline_bootstrap",
|
|
48441
|
+
historicalEvidenceOnly: ["recoveryHints", "ledger.summary", "queue.summary"]
|
|
48442
|
+
},
|
|
47873
48443
|
nodes: nodeStatuses,
|
|
47874
48444
|
queue: { tasks: queue, summary: queueSummary },
|
|
47875
48445
|
ledger: { entries: ledgerEntries, summary: ledgerSummary }
|
|
@@ -55948,6 +56518,7 @@ async function initDaemonComponents(config2) {
|
|
|
55948
56518
|
sessionHostControl: config2.sessionHostControl,
|
|
55949
56519
|
statusInstanceId: config2.statusInstanceId,
|
|
55950
56520
|
statusVersion: config2.statusVersion,
|
|
56521
|
+
getMeshPeerConnectionStatus: config2.getMeshPeerConnectionStatus,
|
|
55951
56522
|
getCdpLogFn: config2.getCdpLogFn || ((ideType) => LOG.forComponent(`CDP:${ideType}`).asLogFn())
|
|
55952
56523
|
});
|
|
55953
56524
|
poller = new AgentStreamPoller({
|
|
@@ -56249,6 +56820,7 @@ __export(src_exports, {
|
|
|
56249
56820
|
prepareSessionChatTailUpdate: () => prepareSessionChatTailUpdate,
|
|
56250
56821
|
prepareSessionModalUpdate: () => prepareSessionModalUpdate,
|
|
56251
56822
|
probeCdpPort: () => probeCdpPort,
|
|
56823
|
+
queuePendingMeshCoordinatorEvent: () => queuePendingMeshCoordinatorEvent,
|
|
56252
56824
|
readChatHistory: () => readChatHistory,
|
|
56253
56825
|
readLedgerEntries: () => readLedgerEntries,
|
|
56254
56826
|
readLedgerSlice: () => readLedgerSlice,
|
|
@@ -58292,7 +58864,7 @@ var require_filesystem = __commonJS({
|
|
|
58292
58864
|
var LDD_PATH = "/usr/bin/ldd";
|
|
58293
58865
|
var SELF_PATH = "/proc/self/exe";
|
|
58294
58866
|
var MAX_LENGTH = 2048;
|
|
58295
|
-
var
|
|
58867
|
+
var readFileSync23 = (path35) => {
|
|
58296
58868
|
const fd = fs20.openSync(path35, "r");
|
|
58297
58869
|
const buffer = Buffer.alloc(MAX_LENGTH);
|
|
58298
58870
|
const bytesRead = fs20.readSync(fd, buffer, 0, MAX_LENGTH, 0);
|
|
@@ -58317,7 +58889,7 @@ var require_filesystem = __commonJS({
|
|
|
58317
58889
|
module2.exports = {
|
|
58318
58890
|
LDD_PATH,
|
|
58319
58891
|
SELF_PATH,
|
|
58320
|
-
readFileSync:
|
|
58892
|
+
readFileSync: readFileSync23,
|
|
58321
58893
|
readFile: readFile2
|
|
58322
58894
|
};
|
|
58323
58895
|
}
|
|
@@ -58366,7 +58938,7 @@ var require_detect_libc = __commonJS({
|
|
|
58366
58938
|
"use strict";
|
|
58367
58939
|
var childProcess = require("child_process");
|
|
58368
58940
|
var { isLinux: isLinux2, getReport } = require_process();
|
|
58369
|
-
var { LDD_PATH, SELF_PATH, readFile: readFile2, readFileSync:
|
|
58941
|
+
var { LDD_PATH, SELF_PATH, readFile: readFile2, readFileSync: readFileSync23 } = require_filesystem();
|
|
58370
58942
|
var { interpreterPath } = require_elf();
|
|
58371
58943
|
var cachedFamilyInterpreter;
|
|
58372
58944
|
var cachedFamilyFilesystem;
|
|
@@ -58458,7 +59030,7 @@ var require_detect_libc = __commonJS({
|
|
|
58458
59030
|
}
|
|
58459
59031
|
cachedFamilyFilesystem = null;
|
|
58460
59032
|
try {
|
|
58461
|
-
const lddContent =
|
|
59033
|
+
const lddContent = readFileSync23(LDD_PATH);
|
|
58462
59034
|
cachedFamilyFilesystem = getFamilyFromLddContent(lddContent);
|
|
58463
59035
|
} catch (e) {
|
|
58464
59036
|
}
|
|
@@ -58483,7 +59055,7 @@ var require_detect_libc = __commonJS({
|
|
|
58483
59055
|
}
|
|
58484
59056
|
cachedFamilyInterpreter = null;
|
|
58485
59057
|
try {
|
|
58486
|
-
const selfContent =
|
|
59058
|
+
const selfContent = readFileSync23(SELF_PATH);
|
|
58487
59059
|
const path35 = interpreterPath(selfContent);
|
|
58488
59060
|
cachedFamilyInterpreter = familyFromInterpreterPath(path35);
|
|
58489
59061
|
} catch (e) {
|
|
@@ -58547,7 +59119,7 @@ var require_detect_libc = __commonJS({
|
|
|
58547
59119
|
}
|
|
58548
59120
|
cachedVersionFilesystem = null;
|
|
58549
59121
|
try {
|
|
58550
|
-
const lddContent =
|
|
59122
|
+
const lddContent = readFileSync23(LDD_PATH);
|
|
58551
59123
|
const versionMatch = lddContent.match(RE_GLIBC_VERSION);
|
|
58552
59124
|
if (versionMatch) {
|
|
58553
59125
|
cachedVersionFilesystem = versionMatch[1];
|
|
@@ -65989,25 +66561,25 @@ function resolvePackageVersion(options) {
|
|
|
65989
66561
|
const injectedVersion = options?.injectedVersion || "unknown";
|
|
65990
66562
|
const dir = options?.dirname || __dirname;
|
|
65991
66563
|
const possiblePaths = [
|
|
65992
|
-
(0,
|
|
65993
|
-
(0,
|
|
65994
|
-
(0,
|
|
66564
|
+
(0, import_path8.join)(dir, "..", "..", "package.json"),
|
|
66565
|
+
(0, import_path8.join)(dir, "..", "package.json"),
|
|
66566
|
+
(0, import_path8.join)(dir, "package.json")
|
|
65995
66567
|
];
|
|
65996
66568
|
for (const p of possiblePaths) {
|
|
65997
66569
|
try {
|
|
65998
|
-
const data = JSON.parse((0,
|
|
66570
|
+
const data = JSON.parse((0, import_fs12.readFileSync)(p, "utf-8"));
|
|
65999
66571
|
if (data.version) return data.version;
|
|
66000
66572
|
} catch {
|
|
66001
66573
|
}
|
|
66002
66574
|
}
|
|
66003
66575
|
return injectedVersion;
|
|
66004
66576
|
}
|
|
66005
|
-
var
|
|
66577
|
+
var import_fs12, import_path8;
|
|
66006
66578
|
var init_version = __esm({
|
|
66007
66579
|
"src/version.ts"() {
|
|
66008
66580
|
"use strict";
|
|
66009
|
-
|
|
66010
|
-
|
|
66581
|
+
import_fs12 = require("fs");
|
|
66582
|
+
import_path8 = require("path");
|
|
66011
66583
|
}
|
|
66012
66584
|
});
|
|
66013
66585
|
|
|
@@ -66040,11 +66612,30 @@ var init_daemon_mesh_manager = __esm({
|
|
|
66040
66612
|
nodeDatachannel = null;
|
|
66041
66613
|
peers = /* @__PURE__ */ new Map();
|
|
66042
66614
|
// Map<targetDaemonId, PeerEntry>
|
|
66615
|
+
peerSnapshots = /* @__PURE__ */ new Map();
|
|
66043
66616
|
pendingRequests = /* @__PURE__ */ new Map();
|
|
66044
66617
|
commandCallback;
|
|
66045
66618
|
p2pFailure(message, command, targetDaemonId) {
|
|
66046
66619
|
return new P2pRelayFailureError(message, { command, targetDaemonId });
|
|
66047
66620
|
}
|
|
66621
|
+
updatePeerSnapshot(targetDaemonId, state, patch = {}) {
|
|
66622
|
+
const previous = this.peerSnapshots.get(targetDaemonId);
|
|
66623
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
66624
|
+
this.peerSnapshots.set(targetDaemonId, {
|
|
66625
|
+
perspective: "selected_coordinator",
|
|
66626
|
+
source: "mesh_peer_status",
|
|
66627
|
+
reported: true,
|
|
66628
|
+
state,
|
|
66629
|
+
transport: patch.transport ?? previous?.transport ?? "unknown",
|
|
66630
|
+
reason: patch.reason ?? previous?.reason,
|
|
66631
|
+
lastStateChangeAt: now,
|
|
66632
|
+
lastConnectedAt: patch.lastConnectedAt ?? previous?.lastConnectedAt,
|
|
66633
|
+
lastCommandAt: patch.lastCommandAt ?? previous?.lastCommandAt
|
|
66634
|
+
});
|
|
66635
|
+
}
|
|
66636
|
+
getPeerConnectionStatus(targetDaemonId) {
|
|
66637
|
+
return this.peerSnapshots.get(targetDaemonId) ?? null;
|
|
66638
|
+
}
|
|
66048
66639
|
invalidatePeer(targetDaemonId, reason, options = {}) {
|
|
66049
66640
|
const peer = this.peers.get(targetDaemonId);
|
|
66050
66641
|
if (peer?.commandQueue) {
|
|
@@ -66059,6 +66650,11 @@ var init_daemon_mesh_manager = __esm({
|
|
|
66059
66650
|
pending.reject(this.p2pFailure(reason, pending.command, targetDaemonId));
|
|
66060
66651
|
}
|
|
66061
66652
|
}
|
|
66653
|
+
const snapshotState = peer?.state === "closed" ? "closed" : peer?.state === "disconnected" ? "disconnected" : "failed";
|
|
66654
|
+
this.updatePeerSnapshot(targetDaemonId, snapshotState, {
|
|
66655
|
+
reason,
|
|
66656
|
+
transport: peer?.isRelay === true ? "relay" : peer?.isRelay === false ? "direct" : "unknown"
|
|
66657
|
+
});
|
|
66062
66658
|
if (options.closeResources !== false && peer) {
|
|
66063
66659
|
try {
|
|
66064
66660
|
peer.dataChannel?.close?.();
|
|
@@ -66091,6 +66687,7 @@ var init_daemon_mesh_manager = __esm({
|
|
|
66091
66687
|
"send_chat",
|
|
66092
66688
|
"read_chat",
|
|
66093
66689
|
"get_chat_debug_bundle",
|
|
66690
|
+
"get_pending_mesh_events",
|
|
66094
66691
|
"git_status",
|
|
66095
66692
|
"git_diff_summary",
|
|
66096
66693
|
"launch_cli",
|
|
@@ -66178,6 +66775,20 @@ var init_daemon_mesh_manager = __esm({
|
|
|
66178
66775
|
if (!peer) {
|
|
66179
66776
|
throw this.p2pFailure("Failed to initiate P2P connection entry", command, targetDaemonId);
|
|
66180
66777
|
}
|
|
66778
|
+
const lastCommandAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
66779
|
+
if (peer.state === "connected") {
|
|
66780
|
+
this.updatePeerSnapshot(targetDaemonId, "connected", {
|
|
66781
|
+
transport: peer.isRelay === true ? "relay" : peer.isRelay === false ? "direct" : "unknown",
|
|
66782
|
+
lastConnectedAt: this.peerSnapshots.get(targetDaemonId)?.lastConnectedAt,
|
|
66783
|
+
lastCommandAt
|
|
66784
|
+
});
|
|
66785
|
+
} else {
|
|
66786
|
+
this.updatePeerSnapshot(targetDaemonId, "connecting", {
|
|
66787
|
+
transport: peer.isRelay === true ? "relay" : peer.isRelay === false ? "direct" : "unknown",
|
|
66788
|
+
reason: "Waiting for mesh DataChannel to open.",
|
|
66789
|
+
lastCommandAt
|
|
66790
|
+
});
|
|
66791
|
+
}
|
|
66181
66792
|
return new Promise((resolve20, reject) => {
|
|
66182
66793
|
const requestId = `req_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
|
|
66183
66794
|
const timer = setTimeout(() => {
|
|
@@ -66321,6 +66932,9 @@ var init_daemon_mesh_manager = __esm({
|
|
|
66321
66932
|
remoteDescriptionSet: false
|
|
66322
66933
|
};
|
|
66323
66934
|
this.peers.set(targetDaemonId, entry);
|
|
66935
|
+
this.updatePeerSnapshot(targetDaemonId, "connecting", {
|
|
66936
|
+
reason: isInitiator ? "P2P mesh connection initiated by the selected coordinator." : "Waiting for the remote daemon to finish the mesh DataChannel handshake."
|
|
66937
|
+
});
|
|
66324
66938
|
pc.onLocalDescription((sdp, type2) => {
|
|
66325
66939
|
this.serverConn.sendMeshCommand(targetDaemonId, type2 === "offer" ? "mesh_p2p_offer" : "mesh_p2p_answer", { sdp, type: type2 });
|
|
66326
66940
|
});
|
|
@@ -66331,7 +66945,26 @@ var init_daemon_mesh_manager = __esm({
|
|
|
66331
66945
|
LOG.info("Mesh", `[Mesh] P2P state with ${targetDaemonId.slice(0, 12)}: ${state}`);
|
|
66332
66946
|
if (state === "connected") {
|
|
66333
66947
|
entry.state = "connected";
|
|
66948
|
+
let transport = "unknown";
|
|
66949
|
+
try {
|
|
66950
|
+
const pair = pc.getSelectedCandidatePair?.();
|
|
66951
|
+
if (pair) {
|
|
66952
|
+
const localType = pair.local?.type || "unknown";
|
|
66953
|
+
const remoteType = pair.remote?.type || "unknown";
|
|
66954
|
+
entry.isRelay = localType === "relay" || remoteType === "relay";
|
|
66955
|
+
transport = entry.isRelay ? "relay" : "direct";
|
|
66956
|
+
LOG.info("Mesh", `[Mesh] Candidate pair with ${targetDaemonId.slice(0, 12)}: local=${localType} remote=${remoteType} \u2192 ${transport}`);
|
|
66957
|
+
}
|
|
66958
|
+
} catch {
|
|
66959
|
+
transport = entry.isRelay === true ? "relay" : entry.isRelay === false ? "direct" : "unknown";
|
|
66960
|
+
}
|
|
66961
|
+
this.updatePeerSnapshot(targetDaemonId, "connected", {
|
|
66962
|
+
transport,
|
|
66963
|
+
reason: transport === "relay" ? "Connected over TURN relay." : transport === "direct" ? "Connected directly peer-to-peer." : "Connected, but selected candidate pair details are unavailable.",
|
|
66964
|
+
lastConnectedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
66965
|
+
});
|
|
66334
66966
|
} else if (state === "failed" || state === "closed" || state === "disconnected") {
|
|
66967
|
+
entry.state = state;
|
|
66335
66968
|
this.invalidatePeer(targetDaemonId, `P2P state changed to ${state}`, { rejectPending: true, closeResources: false });
|
|
66336
66969
|
}
|
|
66337
66970
|
});
|
|
@@ -66349,6 +66982,11 @@ var init_daemon_mesh_manager = __esm({
|
|
|
66349
66982
|
dc.onOpen(() => {
|
|
66350
66983
|
LOG.info("Mesh", `[Mesh] DataChannel OPEN with ${targetDaemonId.slice(0, 12)}`);
|
|
66351
66984
|
entry.state = "connected";
|
|
66985
|
+
this.updatePeerSnapshot(targetDaemonId, "connected", {
|
|
66986
|
+
transport: entry.isRelay === true ? "relay" : entry.isRelay === false ? "direct" : "unknown",
|
|
66987
|
+
reason: entry.isRelay === true ? "Connected over TURN relay." : entry.isRelay === false ? "Connected directly peer-to-peer." : "DataChannel open; transport details not reported yet.",
|
|
66988
|
+
lastConnectedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
66989
|
+
});
|
|
66352
66990
|
if (entry.commandQueue) {
|
|
66353
66991
|
const queue = entry.commandQueue;
|
|
66354
66992
|
entry.commandQueue = [];
|
|
@@ -66628,6 +67266,7 @@ var init_adhdev_daemon = __esm({
|
|
|
66628
67266
|
"use strict";
|
|
66629
67267
|
init_server_connection();
|
|
66630
67268
|
init_src();
|
|
67269
|
+
init_mesh_events();
|
|
66631
67270
|
init_daemon_p2p2();
|
|
66632
67271
|
init_screenshot_controller();
|
|
66633
67272
|
init_session_host();
|
|
@@ -66644,7 +67283,7 @@ var init_adhdev_daemon = __esm({
|
|
|
66644
67283
|
init_version();
|
|
66645
67284
|
init_src();
|
|
66646
67285
|
init_runtime_defaults();
|
|
66647
|
-
pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.
|
|
67286
|
+
pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.30" });
|
|
66648
67287
|
AdhdevDaemon = class _AdhdevDaemon {
|
|
66649
67288
|
localHttpServer = null;
|
|
66650
67289
|
localWss = null;
|
|
@@ -67168,6 +67807,7 @@ ${err?.stack || ""}`);
|
|
|
67168
67807
|
if (!this.meshManager) throw new Error("Mesh manager not initialized");
|
|
67169
67808
|
return this.meshManager.sendCommand(daemonId, command, args);
|
|
67170
67809
|
},
|
|
67810
|
+
getMeshPeerConnectionStatus: (daemonId) => this.meshManager?.getPeerConnectionStatus(daemonId) ?? null,
|
|
67171
67811
|
onStatusChange: () => {
|
|
67172
67812
|
this.invalidateHotChatSnapshotCache();
|
|
67173
67813
|
this.statusReporter?.onStatusChange();
|
|
@@ -67537,6 +68177,7 @@ ${err?.stack || ""}`);
|
|
|
67537
68177
|
const meshId = this.readMeshString(settings.meshNodeFor);
|
|
67538
68178
|
const coordinatorDaemonId = this.readMeshString(settings.meshCoordinatorDaemonId);
|
|
67539
68179
|
if (!meshId || !coordinatorDaemonId) return;
|
|
68180
|
+
const relayTimestamp = typeof event.timestamp === "number" && Number.isFinite(event.timestamp) ? event.timestamp : this.readMeshString(event.timestamp) || void 0;
|
|
67540
68181
|
const payload = {
|
|
67541
68182
|
event: this.readMeshString(event.event),
|
|
67542
68183
|
meshId,
|
|
@@ -67545,7 +68186,8 @@ ${err?.stack || ""}`);
|
|
|
67545
68186
|
targetSessionId: this.readMeshString(event.targetSessionId) || instanceId,
|
|
67546
68187
|
providerType: this.readMeshString(event.providerType),
|
|
67547
68188
|
providerSessionId: this.readMeshString(event.providerSessionId),
|
|
67548
|
-
finalSummary: this.readMeshString(event.finalSummary) || this.readMeshString(event.summary)
|
|
68189
|
+
finalSummary: this.readMeshString(event.finalSummary) || this.readMeshString(event.summary),
|
|
68190
|
+
...relayTimestamp !== void 0 ? { timestamp: relayTimestamp } : {}
|
|
67549
68191
|
};
|
|
67550
68192
|
if (coordinatorDaemonId === localDaemonId) {
|
|
67551
68193
|
try {
|
|
@@ -67560,6 +68202,22 @@ ${err?.stack || ""}`);
|
|
|
67560
68202
|
await this.meshManager.sendCommand(coordinatorDaemonId, "mesh_forward_event", payload);
|
|
67561
68203
|
LOG.info("MeshEvents", `Relayed ${payload.event} for mesh ${meshId} to coordinator daemon ${coordinatorDaemonId.slice(0, 12)}\u2026`);
|
|
67562
68204
|
} catch (error48) {
|
|
68205
|
+
queuePendingMeshCoordinatorEvent({
|
|
68206
|
+
event: payload.event,
|
|
68207
|
+
meshId,
|
|
68208
|
+
nodeLabel: payload.nodeId ? `Node '${payload.nodeId}'` : payload.workspace ? `Agent at ${payload.workspace}` : "Remote agent",
|
|
68209
|
+
nodeId: payload.nodeId || void 0,
|
|
68210
|
+
workspace: payload.workspace || void 0,
|
|
68211
|
+
metadataEvent: {
|
|
68212
|
+
targetSessionId: payload.targetSessionId,
|
|
68213
|
+
providerType: payload.providerType,
|
|
68214
|
+
providerSessionId: payload.providerSessionId,
|
|
68215
|
+
finalSummary: payload.finalSummary,
|
|
68216
|
+
workspace: payload.workspace,
|
|
68217
|
+
...payload.timestamp !== void 0 ? { timestamp: payload.timestamp } : {}
|
|
68218
|
+
},
|
|
68219
|
+
queuedAt: Date.now()
|
|
68220
|
+
});
|
|
67563
68221
|
LOG.warn("MeshEvents", `Failed to relay ${payload.event} for mesh ${meshId}: ${error48?.message || error48}`);
|
|
67564
68222
|
}
|
|
67565
68223
|
}
|
|
@@ -82608,7 +83266,7 @@ var require_buffer_list = __commonJS({
|
|
|
82608
83266
|
}
|
|
82609
83267
|
}, {
|
|
82610
83268
|
key: "join",
|
|
82611
|
-
value: function
|
|
83269
|
+
value: function join37(s) {
|
|
82612
83270
|
if (this.length === 0) return "";
|
|
82613
83271
|
var p = this.head;
|
|
82614
83272
|
var ret = "" + p.data;
|
|
@@ -96667,13 +97325,13 @@ function splitStringBySpace(str2) {
|
|
|
96667
97325
|
}
|
|
96668
97326
|
return pieces;
|
|
96669
97327
|
}
|
|
96670
|
-
var import_chardet, import_child_process14,
|
|
97328
|
+
var import_chardet, import_child_process14, import_fs13, import_node_path3, import_node_os3, import_node_crypto3, import_iconv_lite, ExternalEditor;
|
|
96671
97329
|
var init_esm4 = __esm({
|
|
96672
97330
|
"../../node_modules/@inquirer/external-editor/dist/esm/index.js"() {
|
|
96673
97331
|
"use strict";
|
|
96674
97332
|
import_chardet = __toESM(require_lib2(), 1);
|
|
96675
97333
|
import_child_process14 = require("child_process");
|
|
96676
|
-
|
|
97334
|
+
import_fs13 = require("fs");
|
|
96677
97335
|
import_node_path3 = __toESM(require("path"), 1);
|
|
96678
97336
|
import_node_os3 = __toESM(require("os"), 1);
|
|
96679
97337
|
import_node_crypto3 = require("crypto");
|
|
@@ -96749,14 +97407,14 @@ var init_esm4 = __esm({
|
|
|
96749
97407
|
if (Object.prototype.hasOwnProperty.call(this.fileOptions, "mode")) {
|
|
96750
97408
|
opt.mode = this.fileOptions.mode;
|
|
96751
97409
|
}
|
|
96752
|
-
(0,
|
|
97410
|
+
(0, import_fs13.writeFileSync)(this.tempFile, this.text, opt);
|
|
96753
97411
|
} catch (createFileError) {
|
|
96754
97412
|
throw new CreateFileError(createFileError);
|
|
96755
97413
|
}
|
|
96756
97414
|
}
|
|
96757
97415
|
readTemporaryFile() {
|
|
96758
97416
|
try {
|
|
96759
|
-
const tempFileBuffer = (0,
|
|
97417
|
+
const tempFileBuffer = (0, import_fs13.readFileSync)(this.tempFile);
|
|
96760
97418
|
if (tempFileBuffer.length === 0) {
|
|
96761
97419
|
this.text = "";
|
|
96762
97420
|
} else {
|
|
@@ -96772,7 +97430,7 @@ var init_esm4 = __esm({
|
|
|
96772
97430
|
}
|
|
96773
97431
|
removeTemporaryFile() {
|
|
96774
97432
|
try {
|
|
96775
|
-
(0,
|
|
97433
|
+
(0, import_fs13.unlinkSync)(this.tempFile);
|
|
96776
97434
|
} catch (removeFileError) {
|
|
96777
97435
|
throw new RemoveFileError(removeFileError);
|
|
96778
97436
|
}
|