adhdev 0.9.82-rc.57 → 0.9.82-rc.59
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 +430 -67
- package/dist/cli/index.js.map +1 -1
- package/dist/index.js +430 -67
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/vendor/mcp-server/index.js +114 -20
- package/vendor/mcp-server/index.js.map +1 -1
package/dist/cli/index.js
CHANGED
|
@@ -6541,6 +6541,7 @@ __export(mesh_ledger_exports, {
|
|
|
6541
6541
|
getSessionRecoveryContext: () => getSessionRecoveryContext,
|
|
6542
6542
|
isIntentionalCleanupStopEntry: () => isIntentionalCleanupStopEntry,
|
|
6543
6543
|
meshLedgerEvents: () => meshLedgerEvents,
|
|
6544
|
+
normalizeMeshWorkerResult: () => normalizeMeshWorkerResult,
|
|
6544
6545
|
readLedgerEntries: () => readLedgerEntries,
|
|
6545
6546
|
readLedgerSlice: () => readLedgerSlice
|
|
6546
6547
|
});
|
|
@@ -6564,6 +6565,86 @@ function getRotatedPath(meshId, index) {
|
|
|
6564
6565
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
6565
6566
|
return (0, import_path4.join)(getLedgerDir(), `${safe}.${index}.jsonl`);
|
|
6566
6567
|
}
|
|
6568
|
+
function readNonEmptyString(value) {
|
|
6569
|
+
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
6570
|
+
}
|
|
6571
|
+
function readStringArray(value) {
|
|
6572
|
+
if (!Array.isArray(value)) return [];
|
|
6573
|
+
return value.map((item) => readNonEmptyString(item)).filter(Boolean);
|
|
6574
|
+
}
|
|
6575
|
+
function extractJsonObjectFromSummary(summary) {
|
|
6576
|
+
const text = readNonEmptyString(summary);
|
|
6577
|
+
if (!text) return void 0;
|
|
6578
|
+
const fenced = text.match(/```(?:json)?\s*([\s\S]*?)```/i);
|
|
6579
|
+
const candidates = [fenced?.[1], text].filter(Boolean);
|
|
6580
|
+
for (const candidate of candidates) {
|
|
6581
|
+
const trimmed = candidate.trim();
|
|
6582
|
+
if (!trimmed.startsWith("{") || !trimmed.endsWith("}")) continue;
|
|
6583
|
+
try {
|
|
6584
|
+
const parsed = JSON.parse(trimmed);
|
|
6585
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed;
|
|
6586
|
+
} catch {
|
|
6587
|
+
}
|
|
6588
|
+
}
|
|
6589
|
+
return void 0;
|
|
6590
|
+
}
|
|
6591
|
+
function normalizeValidationResults(value) {
|
|
6592
|
+
if (!Array.isArray(value)) return [];
|
|
6593
|
+
return value.filter((item) => item && typeof item === "object" && !Array.isArray(item)).map((item) => {
|
|
6594
|
+
const status = ["passed", "failed", "skipped", "unknown"].includes(item.status) ? item.status : "unknown";
|
|
6595
|
+
return {
|
|
6596
|
+
...readNonEmptyString(item.command) ? { command: readNonEmptyString(item.command) } : {},
|
|
6597
|
+
status,
|
|
6598
|
+
...Number.isFinite(Number(item.durationMs)) ? { durationMs: Number(item.durationMs) } : {},
|
|
6599
|
+
...readNonEmptyString(item.outputPath) ? { outputPath: readNonEmptyString(item.outputPath) } : {},
|
|
6600
|
+
...readNonEmptyString(item.summary) ? { summary: readNonEmptyString(item.summary) } : {}
|
|
6601
|
+
};
|
|
6602
|
+
});
|
|
6603
|
+
}
|
|
6604
|
+
function normalizeProcessArtifacts(value) {
|
|
6605
|
+
if (!Array.isArray(value)) return [];
|
|
6606
|
+
const kinds = /* @__PURE__ */ new Set(["process", "log", "port", "window", "session", "file", "url", "other"]);
|
|
6607
|
+
return value.filter((item) => item && typeof item === "object" && !Array.isArray(item)).map((item) => ({
|
|
6608
|
+
kind: kinds.has(item.kind) ? item.kind : "other",
|
|
6609
|
+
...readNonEmptyString(item.id) ? { id: readNonEmptyString(item.id) } : {},
|
|
6610
|
+
...readNonEmptyString(item.label) ? { label: readNonEmptyString(item.label) } : {},
|
|
6611
|
+
...readNonEmptyString(item.locator) ? { locator: readNonEmptyString(item.locator) } : {},
|
|
6612
|
+
...Number.isFinite(Number(item.pid)) ? { pid: Number(item.pid) } : {},
|
|
6613
|
+
...Number.isFinite(Number(item.port)) ? { port: Number(item.port) } : {},
|
|
6614
|
+
...readNonEmptyString(item.url) ? { url: readNonEmptyString(item.url) } : {},
|
|
6615
|
+
...readNonEmptyString(item.path) ? { path: readNonEmptyString(item.path) } : {},
|
|
6616
|
+
...readNonEmptyString(item.sessionId) ? { sessionId: readNonEmptyString(item.sessionId) } : {},
|
|
6617
|
+
...typeof item.keepRunning === "boolean" ? { keepRunning: item.keepRunning } : {},
|
|
6618
|
+
...item.metadata && typeof item.metadata === "object" && !Array.isArray(item.metadata) ? { metadata: item.metadata } : {}
|
|
6619
|
+
}));
|
|
6620
|
+
}
|
|
6621
|
+
function normalizeMeshWorkerResult(input, source = "explicit_metadata") {
|
|
6622
|
+
const raw = input && typeof input === "object" ? input : {};
|
|
6623
|
+
const status = ["completed", "failed", "blocked", "partial", "unknown"].includes(String(raw.status)) ? raw.status : "unknown";
|
|
6624
|
+
const gitStatus = raw.gitStatus && typeof raw.gitStatus === "object" && !Array.isArray(raw.gitStatus) ? raw.gitStatus : void 0;
|
|
6625
|
+
return {
|
|
6626
|
+
status,
|
|
6627
|
+
...readNonEmptyString(raw.classification) ? { classification: readNonEmptyString(raw.classification) } : {},
|
|
6628
|
+
changedFiles: readStringArray(raw.changedFiles),
|
|
6629
|
+
validationResults: normalizeValidationResults(raw.validationResults),
|
|
6630
|
+
...gitStatus ? { gitStatus } : {},
|
|
6631
|
+
processArtifacts: normalizeProcessArtifacts(raw.processArtifacts),
|
|
6632
|
+
errors: readStringArray(raw.errors),
|
|
6633
|
+
...readNonEmptyString(raw.nextAction) ? { nextAction: readNonEmptyString(raw.nextAction) } : {},
|
|
6634
|
+
requiresUserAction: raw.requiresUserAction === true,
|
|
6635
|
+
source
|
|
6636
|
+
};
|
|
6637
|
+
}
|
|
6638
|
+
function resolveWorkerResult(opts) {
|
|
6639
|
+
if (opts.workerResult && typeof opts.workerResult === "object") {
|
|
6640
|
+
return normalizeMeshWorkerResult(opts.workerResult, "explicit_metadata");
|
|
6641
|
+
}
|
|
6642
|
+
const parsed = extractJsonObjectFromSummary(opts.finalSummary);
|
|
6643
|
+
if (parsed) {
|
|
6644
|
+
return normalizeMeshWorkerResult(parsed, "final_summary_json");
|
|
6645
|
+
}
|
|
6646
|
+
return normalizeMeshWorkerResult(void 0, "default");
|
|
6647
|
+
}
|
|
6567
6648
|
function buildTaskCompletionEvidence(opts) {
|
|
6568
6649
|
const providerSessionId = opts.providerSessionId?.trim() || void 0;
|
|
6569
6650
|
const providerType = opts.providerType?.trim() || void 0;
|
|
@@ -6580,6 +6661,7 @@ function buildTaskCompletionEvidence(opts) {
|
|
|
6580
6661
|
providerSessionId,
|
|
6581
6662
|
finalSummaryAvailable: typeof opts.finalSummary === "string" && opts.finalSummary.trim().length > 0
|
|
6582
6663
|
},
|
|
6664
|
+
workerResult: resolveWorkerResult(opts),
|
|
6583
6665
|
git: {
|
|
6584
6666
|
status: "deferred",
|
|
6585
6667
|
reason: "ordinary_completion_git_status_not_checked"
|
|
@@ -7298,16 +7380,45 @@ var mesh_work_queue_exports = {};
|
|
|
7298
7380
|
__export(mesh_work_queue_exports, {
|
|
7299
7381
|
ACTIVE_MESH_QUEUE_STATUSES: () => ACTIVE_MESH_QUEUE_STATUSES,
|
|
7300
7382
|
HISTORICAL_MESH_QUEUE_STATUSES: () => HISTORICAL_MESH_QUEUE_STATUSES,
|
|
7383
|
+
MESH_TASK_MODES: () => MESH_TASK_MODES,
|
|
7301
7384
|
cancelTask: () => cancelTask,
|
|
7302
7385
|
claimNextTask: () => claimNextTask,
|
|
7303
7386
|
enqueueTask: () => enqueueTask,
|
|
7304
7387
|
getMeshQueueStats: () => getMeshQueueStats,
|
|
7305
7388
|
getQueue: () => getQueue,
|
|
7389
|
+
normalizeMeshTaskMode: () => normalizeMeshTaskMode,
|
|
7306
7390
|
recordTaskAutoLaunch: () => recordTaskAutoLaunch,
|
|
7307
7391
|
requeueTask: () => requeueTask,
|
|
7308
7392
|
updateSessionTaskStatus: () => updateSessionTaskStatus,
|
|
7309
|
-
updateTaskStatus: () => updateTaskStatus
|
|
7393
|
+
updateTaskStatus: () => updateTaskStatus,
|
|
7394
|
+
validateMeshTaskModeRequest: () => validateMeshTaskModeRequest
|
|
7310
7395
|
});
|
|
7396
|
+
function normalizeMeshTaskMode(value) {
|
|
7397
|
+
if (typeof value !== "string") return void 0;
|
|
7398
|
+
const normalized = value.trim();
|
|
7399
|
+
return MESH_TASK_MODES.includes(normalized) ? normalized : void 0;
|
|
7400
|
+
}
|
|
7401
|
+
function validateMeshTaskModeRequest(mode, message) {
|
|
7402
|
+
const taskMode = normalizeMeshTaskMode(mode);
|
|
7403
|
+
if (!taskMode) {
|
|
7404
|
+
return { valid: true, violations: [] };
|
|
7405
|
+
}
|
|
7406
|
+
if (taskMode !== "live_debug_readonly") {
|
|
7407
|
+
return { valid: true, taskMode, violations: [] };
|
|
7408
|
+
}
|
|
7409
|
+
const violations = LIVE_DEBUG_READONLY_FORBIDDEN.filter((rule) => rule.pattern.test(message || "")).map((rule) => rule.label);
|
|
7410
|
+
return {
|
|
7411
|
+
valid: violations.length === 0,
|
|
7412
|
+
taskMode,
|
|
7413
|
+
violations,
|
|
7414
|
+
allowedOperations: [
|
|
7415
|
+
"process/log/window/port/session inspection",
|
|
7416
|
+
"read-only filesystem listing/reading",
|
|
7417
|
+
"status probes and keep-running handle reporting",
|
|
7418
|
+
"diagnostic summaries without source edits, commits, checkpoints, pushes, deploys, resets, rebases, or destructive cleanups"
|
|
7419
|
+
]
|
|
7420
|
+
};
|
|
7421
|
+
}
|
|
7311
7422
|
function getQueuePath(meshId) {
|
|
7312
7423
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
7313
7424
|
return (0, import_path5.join)(getLedgerDir(), `${safe}.queue.json`);
|
|
@@ -7358,6 +7469,10 @@ function writeQueue(meshId, queue) {
|
|
|
7358
7469
|
}
|
|
7359
7470
|
function enqueueTask(meshId, message, opts) {
|
|
7360
7471
|
requireMeshHostQueueOwner(opts);
|
|
7472
|
+
const modeValidation = validateMeshTaskModeRequest(opts?.taskMode, message);
|
|
7473
|
+
if (!modeValidation.valid) {
|
|
7474
|
+
throw new Error(`live_debug_readonly_guardrail_violation: forbidden operations (${modeValidation.violations.join(", ")})`);
|
|
7475
|
+
}
|
|
7361
7476
|
return withQueueLock(meshId, () => {
|
|
7362
7477
|
const queue = readQueue(meshId);
|
|
7363
7478
|
const entry = {
|
|
@@ -7365,6 +7480,7 @@ function enqueueTask(meshId, message, opts) {
|
|
|
7365
7480
|
meshId,
|
|
7366
7481
|
message,
|
|
7367
7482
|
status: "pending",
|
|
7483
|
+
taskMode: modeValidation.taskMode,
|
|
7368
7484
|
targetNodeId: opts?.targetNodeId,
|
|
7369
7485
|
targetSessionId: opts?.targetSessionId,
|
|
7370
7486
|
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -7526,7 +7642,7 @@ function getMeshQueueStats(meshId) {
|
|
|
7526
7642
|
}))
|
|
7527
7643
|
};
|
|
7528
7644
|
}
|
|
7529
|
-
var import_fs5, import_path5, import_crypto5, ACTIVE_MESH_QUEUE_STATUSES, HISTORICAL_MESH_QUEUE_STATUSES;
|
|
7645
|
+
var import_fs5, import_path5, import_crypto5, ACTIVE_MESH_QUEUE_STATUSES, HISTORICAL_MESH_QUEUE_STATUSES, MESH_TASK_MODES, LIVE_DEBUG_READONLY_FORBIDDEN;
|
|
7530
7646
|
var init_mesh_work_queue = __esm({
|
|
7531
7647
|
"../../oss/packages/daemon-core/src/mesh/mesh-work-queue.ts"() {
|
|
7532
7648
|
"use strict";
|
|
@@ -7537,6 +7653,164 @@ var init_mesh_work_queue = __esm({
|
|
|
7537
7653
|
init_mesh_host_ownership();
|
|
7538
7654
|
ACTIVE_MESH_QUEUE_STATUSES = ["pending", "assigned"];
|
|
7539
7655
|
HISTORICAL_MESH_QUEUE_STATUSES = ["completed", "failed", "cancelled"];
|
|
7656
|
+
MESH_TASK_MODES = ["code_change", "validation", "live_debug_readonly", "launch_app", "convergence"];
|
|
7657
|
+
LIVE_DEBUG_READONLY_FORBIDDEN = [
|
|
7658
|
+
{ label: "source_edit", pattern: /\b(edit|modify|patch|apply\s+patch|write\s+(?:to\s+)?(?:file|source)|overwrite|delete\s+file|remove\s+file|create\s+file|touch\s+file)\b/i },
|
|
7659
|
+
{ label: "git_mutation", pattern: /\b(?:git\s+(?:add|commit|push|reset|rebase|clean|checkout|switch|merge|tag|restore|rm|mv)|push\b)/i },
|
|
7660
|
+
{ label: "checkpoint", pattern: /\b(checkpoint|mesh_checkpoint)\b/i },
|
|
7661
|
+
{ label: "deploy_or_version_bump", pattern: /\b(deploy|wrangler\s+deploy|version[-\s]?bump|npm\s+version|release)\b/i },
|
|
7662
|
+
{ label: "destructive_shell", pattern: /\b(rm\s+-rf|mv\s+\S+\s+\S+|truncate\s|tee\s+\S+|sed\s+-i)\b/i }
|
|
7663
|
+
];
|
|
7664
|
+
}
|
|
7665
|
+
});
|
|
7666
|
+
|
|
7667
|
+
// ../../oss/packages/daemon-core/src/mesh/mesh-active-work.ts
|
|
7668
|
+
function readString2(value) {
|
|
7669
|
+
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
7670
|
+
}
|
|
7671
|
+
function summarizeMessage(message) {
|
|
7672
|
+
const oneLine = message.replace(/\s+/g, " ").trim();
|
|
7673
|
+
const title = oneLine.length > 96 ? `${oneLine.slice(0, 93)}...` : oneLine;
|
|
7674
|
+
return { title: title || "(untitled task)", summary: oneLine };
|
|
7675
|
+
}
|
|
7676
|
+
function elapsedSince(value, now) {
|
|
7677
|
+
const started = value ? new Date(value).getTime() : Number.NaN;
|
|
7678
|
+
return Number.isFinite(started) ? Math.max(0, now - started) : 0;
|
|
7679
|
+
}
|
|
7680
|
+
function sessionStatusFromNodes(nodes, nodeId, sessionId) {
|
|
7681
|
+
if (!nodeId || !sessionId || !Array.isArray(nodes)) return void 0;
|
|
7682
|
+
const node = nodes.find((item) => readString2(item?.id) === nodeId || readString2(item?.nodeId) === nodeId || readString2(item?.node_id) === nodeId);
|
|
7683
|
+
if (!node) return void 0;
|
|
7684
|
+
const candidates = [];
|
|
7685
|
+
for (const value of [node.sessions, node.activeSessions, node.active_sessions, node.lastProbe?.sessions, node.last_probe?.sessions, node.lastProbe?.status?.sessions, node.last_probe?.status?.sessions]) {
|
|
7686
|
+
if (Array.isArray(value)) candidates.push(...value);
|
|
7687
|
+
}
|
|
7688
|
+
for (const value of [node.activeSession, node.active_session, node.currentSession, node.current_session, node.runtimeSession, node.runtime_session, node.session]) {
|
|
7689
|
+
if (value && typeof value === "object") candidates.push(value);
|
|
7690
|
+
}
|
|
7691
|
+
const session = candidates.find((item) => {
|
|
7692
|
+
const id = readString2(item?.id) || readString2(item?.sessionId) || readString2(item?.session_id) || readString2(item?.runtimeSessionId) || readString2(item?.instanceId);
|
|
7693
|
+
return id === sessionId;
|
|
7694
|
+
});
|
|
7695
|
+
if (!session) return void 0;
|
|
7696
|
+
const raw = `${readString2(session.status) || ""} ${readString2(session.lifecycle) || ""} ${readString2(session.state) || ""} ${readString2(session.activeChat?.status) || ""}`.toLowerCase();
|
|
7697
|
+
if (raw.includes("approval")) return "awaiting_approval";
|
|
7698
|
+
if (raw.includes("generating") || raw.includes("running") || raw.includes("busy")) return "generating";
|
|
7699
|
+
if (raw.includes("failed") || raw.includes("stopped") || raw.includes("terminated") || raw.includes("exited")) return "failed";
|
|
7700
|
+
if (raw.includes("idle") || raw.includes("waiting_input") || raw.includes("ready")) return "idle";
|
|
7701
|
+
return void 0;
|
|
7702
|
+
}
|
|
7703
|
+
function isDirectDispatch(entry) {
|
|
7704
|
+
if (entry.kind !== "task_dispatched") return false;
|
|
7705
|
+
const payload = entry.payload || {};
|
|
7706
|
+
if (payload.source === "direct") return true;
|
|
7707
|
+
const via = readString2(payload.via);
|
|
7708
|
+
return Boolean(via && DIRECT_DISPATCH_VIA.has(via) && payload.source !== "queue");
|
|
7709
|
+
}
|
|
7710
|
+
function directDispatchTaskId(entry) {
|
|
7711
|
+
return readString2(entry.payload?.taskId) || entry.id;
|
|
7712
|
+
}
|
|
7713
|
+
function terminalMatchesDispatch(terminal2, dispatch, taskId) {
|
|
7714
|
+
const terminalTaskId = readString2(terminal2.payload?.taskId);
|
|
7715
|
+
if (terminalTaskId && terminalTaskId === taskId) return true;
|
|
7716
|
+
if (terminalTaskId && terminalTaskId !== taskId) return false;
|
|
7717
|
+
if (dispatch.sessionId && terminal2.sessionId === dispatch.sessionId) return true;
|
|
7718
|
+
return Boolean(dispatch.nodeId && terminal2.nodeId === dispatch.nodeId && !dispatch.sessionId);
|
|
7719
|
+
}
|
|
7720
|
+
function statusFromTerminal(entry) {
|
|
7721
|
+
if (entry.kind === "task_approval_needed") return "awaiting_approval";
|
|
7722
|
+
if (entry.kind === "task_completed") return "idle";
|
|
7723
|
+
return "failed";
|
|
7724
|
+
}
|
|
7725
|
+
function buildMeshActiveWorkSummary(activeWork) {
|
|
7726
|
+
const statusCounts = {
|
|
7727
|
+
pending: 0,
|
|
7728
|
+
assigned: 0,
|
|
7729
|
+
generating: 0,
|
|
7730
|
+
idle: 0,
|
|
7731
|
+
failed: 0,
|
|
7732
|
+
awaiting_approval: 0
|
|
7733
|
+
};
|
|
7734
|
+
const sourceCounts = { queue: 0, direct: 0 };
|
|
7735
|
+
for (const item of activeWork) {
|
|
7736
|
+
sourceCounts[item.source] += 1;
|
|
7737
|
+
statusCounts[item.status] += 1;
|
|
7738
|
+
}
|
|
7739
|
+
return {
|
|
7740
|
+
totalActiveCount: activeWork.length,
|
|
7741
|
+
queueActiveCount: sourceCounts.queue,
|
|
7742
|
+
directActiveCount: sourceCounts.direct,
|
|
7743
|
+
awaitingApprovalCount: statusCounts.awaiting_approval,
|
|
7744
|
+
generatingCount: statusCounts.generating,
|
|
7745
|
+
failedCount: statusCounts.failed,
|
|
7746
|
+
idleCount: statusCounts.idle,
|
|
7747
|
+
sourceCounts,
|
|
7748
|
+
statusCounts
|
|
7749
|
+
};
|
|
7750
|
+
}
|
|
7751
|
+
function buildMeshActiveWork(opts) {
|
|
7752
|
+
const now = opts.now ?? Date.now();
|
|
7753
|
+
const records = [];
|
|
7754
|
+
for (const task of opts.queue || []) {
|
|
7755
|
+
if (task.status !== "pending" && task.status !== "assigned") continue;
|
|
7756
|
+
const { title, summary } = summarizeMessage(task.message || "");
|
|
7757
|
+
records.push({
|
|
7758
|
+
taskId: task.id,
|
|
7759
|
+
source: "queue",
|
|
7760
|
+
status: task.status,
|
|
7761
|
+
nodeId: task.assignedNodeId || task.targetNodeId,
|
|
7762
|
+
sessionId: task.assignedSessionId || task.targetSessionId,
|
|
7763
|
+
taskTitle: title,
|
|
7764
|
+
taskSummary: summary,
|
|
7765
|
+
message: task.message,
|
|
7766
|
+
taskMode: task.taskMode,
|
|
7767
|
+
createdAt: task.createdAt,
|
|
7768
|
+
updatedAt: task.updatedAt,
|
|
7769
|
+
dispatchedAt: task.dispatchTimestamp,
|
|
7770
|
+
elapsedMs: elapsedSince(task.dispatchTimestamp || task.createdAt, now)
|
|
7771
|
+
});
|
|
7772
|
+
}
|
|
7773
|
+
const ledgerEntries = (opts.ledgerEntries || []).slice().sort((a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime());
|
|
7774
|
+
const terminals = ledgerEntries.filter((entry) => TERMINAL_LEDGER_KINDS.has(entry.kind) || entry.kind === "task_approval_needed");
|
|
7775
|
+
for (const dispatch of ledgerEntries.filter(isDirectDispatch)) {
|
|
7776
|
+
const taskId = directDispatchTaskId(dispatch);
|
|
7777
|
+
const terminal2 = terminals.filter((entry) => new Date(entry.timestamp).getTime() >= new Date(dispatch.timestamp).getTime()).find((entry) => terminalMatchesDispatch(entry, dispatch, taskId));
|
|
7778
|
+
const terminalStatus = terminal2 ? statusFromTerminal(terminal2) : void 0;
|
|
7779
|
+
const liveStatus = sessionStatusFromNodes(opts.nodes, dispatch.nodeId, dispatch.sessionId);
|
|
7780
|
+
const status = terminalStatus || liveStatus || "assigned";
|
|
7781
|
+
const terminalRow = Boolean(terminal2 && terminal2.kind !== "task_approval_needed");
|
|
7782
|
+
if (terminalRow && opts.includeTerminalDirect !== true) continue;
|
|
7783
|
+
const message = readString2(dispatch.payload?.message) || readString2(dispatch.payload?.summary) || "";
|
|
7784
|
+
const { title, summary } = summarizeMessage(message);
|
|
7785
|
+
records.push({
|
|
7786
|
+
taskId,
|
|
7787
|
+
source: "direct",
|
|
7788
|
+
status,
|
|
7789
|
+
nodeId: dispatch.nodeId,
|
|
7790
|
+
sessionId: dispatch.sessionId,
|
|
7791
|
+
providerType: dispatch.providerType || readString2(dispatch.payload?.providerType),
|
|
7792
|
+
taskTitle: readString2(dispatch.payload?.taskTitle) || title,
|
|
7793
|
+
taskSummary: readString2(dispatch.payload?.taskSummary) || summary,
|
|
7794
|
+
message,
|
|
7795
|
+
taskMode: readString2(dispatch.payload?.taskMode),
|
|
7796
|
+
createdAt: dispatch.timestamp,
|
|
7797
|
+
updatedAt: terminal2?.timestamp || dispatch.timestamp,
|
|
7798
|
+
dispatchedAt: dispatch.timestamp,
|
|
7799
|
+
elapsedMs: elapsedSince(dispatch.timestamp, now),
|
|
7800
|
+
terminal: terminalRow,
|
|
7801
|
+
terminalKind: terminal2?.kind,
|
|
7802
|
+
terminalAt: terminal2?.timestamp
|
|
7803
|
+
});
|
|
7804
|
+
}
|
|
7805
|
+
records.sort((a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime());
|
|
7806
|
+
return { activeWork: records, summary: buildMeshActiveWorkSummary(records) };
|
|
7807
|
+
}
|
|
7808
|
+
var DIRECT_DISPATCH_VIA, TERMINAL_LEDGER_KINDS;
|
|
7809
|
+
var init_mesh_active_work = __esm({
|
|
7810
|
+
"../../oss/packages/daemon-core/src/mesh/mesh-active-work.ts"() {
|
|
7811
|
+
"use strict";
|
|
7812
|
+
DIRECT_DISPATCH_VIA = /* @__PURE__ */ new Set(["p2p_direct", "local_direct", "mesh_send_task"]);
|
|
7813
|
+
TERMINAL_LEDGER_KINDS = /* @__PURE__ */ new Set(["task_completed", "task_failed", "task_stalled"]);
|
|
7540
7814
|
}
|
|
7541
7815
|
});
|
|
7542
7816
|
|
|
@@ -7901,6 +8175,9 @@ __export(mesh_events_exports, {
|
|
|
7901
8175
|
triggerMeshQueue: () => triggerMeshQueue,
|
|
7902
8176
|
tryAssignQueueTask: () => tryAssignQueueTask
|
|
7903
8177
|
});
|
|
8178
|
+
function readWorkerResultMetadata(event) {
|
|
8179
|
+
return readRecord(event.workerResult) || readRecord(event.meshWorkerResult) || readRecord(event.structuredResult);
|
|
8180
|
+
}
|
|
7904
8181
|
function sweepExpiredRemoteIdleSessions() {
|
|
7905
8182
|
const now = Date.now();
|
|
7906
8183
|
for (const [key, session] of remoteIdleSessions) {
|
|
@@ -7966,20 +8243,28 @@ function clearPendingMeshCoordinatorEvents(meshId) {
|
|
|
7966
8243
|
} catch {
|
|
7967
8244
|
}
|
|
7968
8245
|
}
|
|
7969
|
-
function
|
|
8246
|
+
function readNonEmptyString2(value) {
|
|
7970
8247
|
return typeof value === "string" && value.trim() ? value.trim() : "";
|
|
7971
8248
|
}
|
|
8249
|
+
function readRecord(value) {
|
|
8250
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
8251
|
+
}
|
|
7972
8252
|
function resolveEventSessionId(event, fallback2) {
|
|
7973
|
-
return
|
|
8253
|
+
return readNonEmptyString2(event.targetSessionId) || readNonEmptyString2(event.sessionId) || readNonEmptyString2(event.instanceId) || readNonEmptyString2(fallback2);
|
|
7974
8254
|
}
|
|
7975
8255
|
function isMeshCoordinatorEvent(eventName) {
|
|
7976
8256
|
return typeof eventName === "string" && MESH_COORDINATOR_EVENTS.has(eventName);
|
|
7977
8257
|
}
|
|
7978
8258
|
function formatCompletionMetadata(event) {
|
|
8259
|
+
const completionDiagnostic = event.completionDiagnostic && typeof event.completionDiagnostic === "object" ? event.completionDiagnostic : null;
|
|
8260
|
+
const diagnosticReason = completionDiagnostic ? readNonEmptyString2(completionDiagnostic.blockReason) || "present" : "";
|
|
8261
|
+
const finalAssistantPresent = typeof completionDiagnostic?.finalAssistantPresent === "boolean" ? String(completionDiagnostic.finalAssistantPresent) : "";
|
|
7979
8262
|
const parts = [
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
8263
|
+
readNonEmptyString2(event.targetSessionId) ? `session_id=${readNonEmptyString2(event.targetSessionId)}` : "",
|
|
8264
|
+
readNonEmptyString2(event.providerType) ? `provider=${readNonEmptyString2(event.providerType)}` : "",
|
|
8265
|
+
readNonEmptyString2(event.providerSessionId) ? `provider_session_id=${readNonEmptyString2(event.providerSessionId)}` : "",
|
|
8266
|
+
diagnosticReason ? `completion_diagnostic=${diagnosticReason}` : "",
|
|
8267
|
+
finalAssistantPresent ? `final_assistant=${finalAssistantPresent}` : ""
|
|
7983
8268
|
].filter(Boolean);
|
|
7984
8269
|
return parts.length > 0 ? ` (${parts.join("; ")})` : "";
|
|
7985
8270
|
}
|
|
@@ -8021,7 +8306,7 @@ function readEventTimestamp(value) {
|
|
|
8021
8306
|
return null;
|
|
8022
8307
|
}
|
|
8023
8308
|
function buildMeshCompletionFingerprint(args) {
|
|
8024
|
-
const timestampPart = Number.isFinite(args.timestamp) ? String(args.timestamp) :
|
|
8309
|
+
const timestampPart = Number.isFinite(args.timestamp) ? String(args.timestamp) : readNonEmptyString2(args.finalSummary).slice(0, 200);
|
|
8025
8310
|
return [
|
|
8026
8311
|
args.meshId,
|
|
8027
8312
|
args.event,
|
|
@@ -8099,7 +8384,7 @@ function isTerminalSessionStatus(status) {
|
|
|
8099
8384
|
return ["stopped", "failed", "terminated", "exited", "closed"].includes(status);
|
|
8100
8385
|
}
|
|
8101
8386
|
function isIdleSessionState(state) {
|
|
8102
|
-
const status =
|
|
8387
|
+
const status = readNonEmptyString2(state?.status).toLowerCase();
|
|
8103
8388
|
if (isTerminalSessionStatus(status)) return false;
|
|
8104
8389
|
return status === "idle" || state?.activeChat?.status === "waiting_input";
|
|
8105
8390
|
}
|
|
@@ -8108,15 +8393,15 @@ function isDirtyNode(node) {
|
|
|
8108
8393
|
}
|
|
8109
8394
|
function isLaunchableNode(node) {
|
|
8110
8395
|
if (!node || node.status === "disabled" || node.status === "removed") return false;
|
|
8111
|
-
const health =
|
|
8396
|
+
const health = readNonEmptyString2(node.health).toLowerCase();
|
|
8112
8397
|
if (!health) return true;
|
|
8113
8398
|
return health === "online" || health === "unknown";
|
|
8114
8399
|
}
|
|
8115
8400
|
function localAutoLaunchSkipReason(node) {
|
|
8116
|
-
const daemonId =
|
|
8117
|
-
const machineId =
|
|
8401
|
+
const daemonId = readNonEmptyString2(node?.daemonId);
|
|
8402
|
+
const machineId = readNonEmptyString2(node?.machineId);
|
|
8118
8403
|
const appConfig = loadConfig();
|
|
8119
|
-
const localMachineId =
|
|
8404
|
+
const localMachineId = readNonEmptyString2(appConfig.machineId) || readNonEmptyString2(appConfig.registeredMachineId);
|
|
8120
8405
|
const cloudDaemonId = localMachineId ? `daemon_${localMachineId}` : "";
|
|
8121
8406
|
const standaloneDaemonId = localMachineId ? `standalone_${localMachineId}` : "";
|
|
8122
8407
|
const daemonMatchesLocal = !daemonId || daemonId === cloudDaemonId || daemonId === standaloneDaemonId;
|
|
@@ -8139,10 +8424,10 @@ function liveSessionCountForNode(components, meshId, nodeId) {
|
|
|
8139
8424
|
return components.instanceManager.getByCategory("cli").filter((inst) => {
|
|
8140
8425
|
const state = inst.getState();
|
|
8141
8426
|
const settings = state.settings || {};
|
|
8142
|
-
if (
|
|
8143
|
-
const instNodeId =
|
|
8427
|
+
if (readNonEmptyString2(settings.meshNodeFor) !== meshId) return false;
|
|
8428
|
+
const instNodeId = readNonEmptyString2(settings.meshNodeId) || readNonEmptyString2(settings.nodeId);
|
|
8144
8429
|
if (instNodeId !== nodeId) return false;
|
|
8145
|
-
const status =
|
|
8430
|
+
const status = readNonEmptyString2(state.status).toLowerCase();
|
|
8146
8431
|
return !isTerminalSessionStatus(status);
|
|
8147
8432
|
}).length;
|
|
8148
8433
|
}
|
|
@@ -8234,7 +8519,7 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
|
|
|
8234
8519
|
continue;
|
|
8235
8520
|
}
|
|
8236
8521
|
for (const node of candidateNodes) {
|
|
8237
|
-
const nodeId =
|
|
8522
|
+
const nodeId = readNonEmptyString2(node?.id);
|
|
8238
8523
|
if (!nodeId) continue;
|
|
8239
8524
|
const launchKey = `${meshId}:${nodeId}`;
|
|
8240
8525
|
const cooldownUntil = autoLaunchCooldownUntil.get(launchKey) || 0;
|
|
@@ -8293,7 +8578,7 @@ async function maybeAutoLaunchOneQueueSession(components, meshId, mesh) {
|
|
|
8293
8578
|
autoLaunchCooldownUntil.set(launchKey, Date.now() + AUTO_LAUNCH_COOLDOWN_MS);
|
|
8294
8579
|
return false;
|
|
8295
8580
|
}
|
|
8296
|
-
const sessionId =
|
|
8581
|
+
const sessionId = readNonEmptyString2(launchResult.sessionId) || readNonEmptyString2(launchResult.id) || readNonEmptyString2(launchResult.runtimeSessionId);
|
|
8297
8582
|
if (!sessionId) {
|
|
8298
8583
|
markAutoLaunch(meshId, task.id, { status: "failed", reason: "launch_missing_session_id", nodeId, providerType: resolved.providerType });
|
|
8299
8584
|
autoLaunchCooldownUntil.set(launchKey, Date.now() + AUTO_LAUNCH_COOLDOWN_MS);
|
|
@@ -8320,13 +8605,13 @@ async function triggerMeshQueue(components, meshId) {
|
|
|
8320
8605
|
for (const inst of cliInstances) {
|
|
8321
8606
|
const state = inst.getState();
|
|
8322
8607
|
const settings = state.settings || {};
|
|
8323
|
-
const instMeshId =
|
|
8608
|
+
const instMeshId = readNonEmptyString2(settings.meshNodeFor);
|
|
8324
8609
|
if (instMeshId !== meshId) continue;
|
|
8325
|
-
const nodeId =
|
|
8610
|
+
const nodeId = readNonEmptyString2(settings.meshNodeId) || readNonEmptyString2(settings.nodeId);
|
|
8326
8611
|
if (!nodeId) continue;
|
|
8327
8612
|
if (!isIdleSessionState(state)) continue;
|
|
8328
8613
|
const sessionId = state.instanceId;
|
|
8329
|
-
const providerType = state.type ||
|
|
8614
|
+
const providerType = state.type || readNonEmptyString2(settings.providerType);
|
|
8330
8615
|
if (providerType) {
|
|
8331
8616
|
tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType);
|
|
8332
8617
|
}
|
|
@@ -8388,7 +8673,7 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
8388
8673
|
}
|
|
8389
8674
|
function injectMeshSystemMessage(components, args) {
|
|
8390
8675
|
const eventSessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
|
|
8391
|
-
const eventNodeId =
|
|
8676
|
+
const eventNodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
|
|
8392
8677
|
const intentionalCleanupStop = shouldSuppressIntentionalCleanupStop({
|
|
8393
8678
|
event: args.event,
|
|
8394
8679
|
meshId: args.meshId,
|
|
@@ -8409,10 +8694,10 @@ function injectMeshSystemMessage(components, args) {
|
|
|
8409
8694
|
meshId: args.meshId,
|
|
8410
8695
|
event: args.event,
|
|
8411
8696
|
sessionId: eventSessionId,
|
|
8412
|
-
providerType:
|
|
8413
|
-
providerSessionId:
|
|
8697
|
+
providerType: readNonEmptyString2(args.metadataEvent.providerType) || void 0,
|
|
8698
|
+
providerSessionId: readNonEmptyString2(args.metadataEvent.providerSessionId) || void 0,
|
|
8414
8699
|
timestamp: eventTimestamp,
|
|
8415
|
-
finalSummary:
|
|
8700
|
+
finalSummary: readNonEmptyString2(args.metadataEvent.finalSummary) || void 0
|
|
8416
8701
|
});
|
|
8417
8702
|
if (duplicateCompletion) {
|
|
8418
8703
|
LOG.info("MeshEvents", `Suppressed duplicate completion for mesh ${args.meshId} session ${eventSessionId}`);
|
|
@@ -8422,8 +8707,8 @@ function injectMeshSystemMessage(components, args) {
|
|
|
8422
8707
|
let completedTaskForLedger = null;
|
|
8423
8708
|
if (args.event === "agent:generating_completed") {
|
|
8424
8709
|
const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
|
|
8425
|
-
const nodeId =
|
|
8426
|
-
const providerType =
|
|
8710
|
+
const nodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
|
|
8711
|
+
const providerType = readNonEmptyString2(args.metadataEvent.providerType);
|
|
8427
8712
|
if (sessionId) {
|
|
8428
8713
|
const completedTask = updateSessionTaskStatus(args.meshId, sessionId, "completed", {
|
|
8429
8714
|
occurredAt: eventTimestamp !== null ? new Date(eventTimestamp).toISOString() : void 0
|
|
@@ -8437,8 +8722,11 @@ function injectMeshSystemMessage(components, args) {
|
|
|
8437
8722
|
}
|
|
8438
8723
|
} else if (args.event === "agent:ready") {
|
|
8439
8724
|
const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
|
|
8440
|
-
const nodeId =
|
|
8441
|
-
const providerType =
|
|
8725
|
+
const nodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
|
|
8726
|
+
const providerType = readNonEmptyString2(args.metadataEvent.providerType);
|
|
8727
|
+
const providerSessionId = readNonEmptyString2(args.metadataEvent.providerSessionId) || void 0;
|
|
8728
|
+
const finalSummary = readNonEmptyString2(args.metadataEvent.finalSummary) || void 0;
|
|
8729
|
+
const workerResult = readWorkerResultMetadata(args.metadataEvent);
|
|
8442
8730
|
const completedTask = sessionId ? updateSessionTaskStatus(args.meshId, sessionId, "completed") : null;
|
|
8443
8731
|
if (completedTask) {
|
|
8444
8732
|
completedTaskForLedger = { id: completedTask.id };
|
|
@@ -8453,15 +8741,17 @@ function injectMeshSystemMessage(components, args) {
|
|
|
8453
8741
|
nodeLabel: args.nodeLabel,
|
|
8454
8742
|
taskId: completedTask.id,
|
|
8455
8743
|
completedViaReady: true,
|
|
8456
|
-
providerSessionId
|
|
8457
|
-
finalSummary
|
|
8744
|
+
providerSessionId,
|
|
8745
|
+
finalSummary,
|
|
8746
|
+
workerResult,
|
|
8458
8747
|
evidence: buildTaskCompletionEvidence({
|
|
8459
8748
|
event: "agent:ready",
|
|
8460
8749
|
nodeId,
|
|
8461
8750
|
sessionId,
|
|
8462
8751
|
providerType: providerType || void 0,
|
|
8463
|
-
providerSessionId
|
|
8464
|
-
finalSummary
|
|
8752
|
+
providerSessionId,
|
|
8753
|
+
finalSummary,
|
|
8754
|
+
workerResult
|
|
8465
8755
|
})
|
|
8466
8756
|
}
|
|
8467
8757
|
});
|
|
@@ -8484,13 +8774,13 @@ function injectMeshSystemMessage(components, args) {
|
|
|
8484
8774
|
}
|
|
8485
8775
|
} else if (args.event === "agent:generating_started") {
|
|
8486
8776
|
const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
|
|
8487
|
-
const nodeId =
|
|
8777
|
+
const nodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
|
|
8488
8778
|
if (sessionId && nodeId) {
|
|
8489
8779
|
remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
|
|
8490
8780
|
}
|
|
8491
8781
|
} else if (args.event === "agent:stopped") {
|
|
8492
8782
|
const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
|
|
8493
|
-
const nodeId =
|
|
8783
|
+
const nodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId);
|
|
8494
8784
|
if (sessionId && nodeId) {
|
|
8495
8785
|
remoteIdleSessions.delete(`${nodeId}:${sessionId}`);
|
|
8496
8786
|
}
|
|
@@ -8501,16 +8791,20 @@ function injectMeshSystemMessage(components, args) {
|
|
|
8501
8791
|
const ledgerKind = EVENT_TO_LEDGER_KIND[args.event];
|
|
8502
8792
|
if (ledgerKind) {
|
|
8503
8793
|
try {
|
|
8504
|
-
const ledgerNodeId =
|
|
8794
|
+
const ledgerNodeId = readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId) || void 0;
|
|
8505
8795
|
const ledgerSessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId) || void 0;
|
|
8506
|
-
const ledgerProviderType =
|
|
8796
|
+
const ledgerProviderType = readNonEmptyString2(args.metadataEvent.providerType) || void 0;
|
|
8797
|
+
const providerSessionId = readNonEmptyString2(args.metadataEvent.providerSessionId) || void 0;
|
|
8798
|
+
const finalSummary = readNonEmptyString2(args.metadataEvent.finalSummary) || void 0;
|
|
8799
|
+
const workerResult = readWorkerResultMetadata(args.metadataEvent);
|
|
8507
8800
|
const completionEvidence = ledgerKind === "task_completed" && ledgerNodeId && ledgerSessionId ? buildTaskCompletionEvidence({
|
|
8508
8801
|
event: "agent:generating_completed",
|
|
8509
8802
|
nodeId: ledgerNodeId,
|
|
8510
8803
|
sessionId: ledgerSessionId,
|
|
8511
8804
|
providerType: ledgerProviderType,
|
|
8512
|
-
providerSessionId
|
|
8513
|
-
finalSummary
|
|
8805
|
+
providerSessionId,
|
|
8806
|
+
finalSummary,
|
|
8807
|
+
workerResult
|
|
8514
8808
|
}) : void 0;
|
|
8515
8809
|
appendLedgerEntry(args.meshId, {
|
|
8516
8810
|
kind: ledgerKind,
|
|
@@ -8521,8 +8815,10 @@ function injectMeshSystemMessage(components, args) {
|
|
|
8521
8815
|
event: args.event,
|
|
8522
8816
|
nodeLabel: args.nodeLabel,
|
|
8523
8817
|
taskId: completedTaskForLedger?.id || void 0,
|
|
8524
|
-
providerSessionId
|
|
8525
|
-
finalSummary
|
|
8818
|
+
providerSessionId,
|
|
8819
|
+
finalSummary,
|
|
8820
|
+
workerResult,
|
|
8821
|
+
completionDiagnostic: args.metadataEvent.completionDiagnostic && typeof args.metadataEvent.completionDiagnostic === "object" ? args.metadataEvent.completionDiagnostic : void 0,
|
|
8526
8822
|
evidence: completionEvidence
|
|
8527
8823
|
}
|
|
8528
8824
|
});
|
|
@@ -8537,10 +8833,10 @@ function injectMeshSystemMessage(components, args) {
|
|
|
8537
8833
|
const maxRetries = mesh?.policy?.maxTaskRetries ?? 1;
|
|
8538
8834
|
recoveryContext = getSessionRecoveryContext(args.meshId, {
|
|
8539
8835
|
sessionId: resolveEventSessionId(args.metadataEvent, args.sourceInstanceId) || void 0,
|
|
8540
|
-
nodeId:
|
|
8836
|
+
nodeId: readNonEmptyString2(args.nodeId) || readNonEmptyString2(args.metadataEvent.meshNodeId) || void 0,
|
|
8541
8837
|
maxRetries
|
|
8542
8838
|
});
|
|
8543
|
-
recoveryContext.failedProviderType =
|
|
8839
|
+
recoveryContext.failedProviderType = readNonEmptyString2(args.metadataEvent.providerType) || null;
|
|
8544
8840
|
if (recoveryContext.retryRecommended && recoveryContext.consecutiveNodeFailures > 0) {
|
|
8545
8841
|
appendLedgerEntry(args.meshId, {
|
|
8546
8842
|
kind: "recovery_attempted",
|
|
@@ -8596,7 +8892,7 @@ function injectMeshSystemMessage(components, args) {
|
|
|
8596
8892
|
meshId: args.meshId,
|
|
8597
8893
|
nodeLabel: args.nodeLabel,
|
|
8598
8894
|
nodeId: args.nodeId || void 0,
|
|
8599
|
-
workspace:
|
|
8895
|
+
workspace: readNonEmptyString2(args.metadataEvent.workspace),
|
|
8600
8896
|
metadataEvent: {
|
|
8601
8897
|
...args.metadataEvent,
|
|
8602
8898
|
...recoveryContext ? { recoveryContext } : {}
|
|
@@ -8622,14 +8918,14 @@ function injectMeshSystemMessage(components, args) {
|
|
|
8622
8918
|
return { success: true, forwarded: coordinatorInstances.length };
|
|
8623
8919
|
}
|
|
8624
8920
|
function handleMeshForwardEvent(components, payload) {
|
|
8625
|
-
const eventName =
|
|
8921
|
+
const eventName = readNonEmptyString2(payload.event);
|
|
8626
8922
|
if (!isMeshCoordinatorEvent(eventName)) {
|
|
8627
8923
|
return { success: false, error: "unsupported mesh event" };
|
|
8628
8924
|
}
|
|
8629
|
-
const meshId =
|
|
8925
|
+
const meshId = readNonEmptyString2(payload.meshId);
|
|
8630
8926
|
if (!meshId) return { success: false, error: "meshId required" };
|
|
8631
|
-
const nodeId =
|
|
8632
|
-
const workspace =
|
|
8927
|
+
const nodeId = readNonEmptyString2(payload.nodeId);
|
|
8928
|
+
const workspace = readNonEmptyString2(payload.workspace);
|
|
8633
8929
|
const nodeLabel = nodeId ? `Node '${nodeId}'` : workspace ? `Agent at ${workspace}` : "Remote agent";
|
|
8634
8930
|
return injectMeshSystemMessage(components, {
|
|
8635
8931
|
meshId,
|
|
@@ -8637,41 +8933,41 @@ function handleMeshForwardEvent(components, payload) {
|
|
|
8637
8933
|
nodeLabel,
|
|
8638
8934
|
event: eventName,
|
|
8639
8935
|
metadataEvent: {
|
|
8640
|
-
targetSessionId:
|
|
8641
|
-
providerType:
|
|
8642
|
-
providerSessionId:
|
|
8643
|
-
finalSummary:
|
|
8936
|
+
targetSessionId: readNonEmptyString2(payload.targetSessionId) || readNonEmptyString2(payload.sessionId) || readNonEmptyString2(payload.instanceId),
|
|
8937
|
+
providerType: readNonEmptyString2(payload.providerType),
|
|
8938
|
+
providerSessionId: readNonEmptyString2(payload.providerSessionId),
|
|
8939
|
+
finalSummary: readNonEmptyString2(payload.finalSummary) || readNonEmptyString2(payload.summary),
|
|
8644
8940
|
...payload.timestamp !== void 0 ? { timestamp: payload.timestamp } : {},
|
|
8645
8941
|
intentional: payload.intentional === true,
|
|
8646
8942
|
intentionalStop: payload.intentionalStop === true,
|
|
8647
8943
|
operatorCleanup: payload.operatorCleanup === true,
|
|
8648
|
-
reason:
|
|
8649
|
-
stopReason:
|
|
8650
|
-
cleanupReason:
|
|
8651
|
-
source:
|
|
8944
|
+
reason: readNonEmptyString2(payload.reason),
|
|
8945
|
+
stopReason: readNonEmptyString2(payload.stopReason),
|
|
8946
|
+
cleanupReason: readNonEmptyString2(payload.cleanupReason),
|
|
8947
|
+
source: readNonEmptyString2(payload.source)
|
|
8652
8948
|
}
|
|
8653
8949
|
});
|
|
8654
8950
|
}
|
|
8655
8951
|
function setupMeshEventForwarding(components) {
|
|
8656
8952
|
components.instanceManager.onEvent((event) => {
|
|
8657
8953
|
if (!isMeshCoordinatorEvent(event.event)) return;
|
|
8658
|
-
const instanceId =
|
|
8954
|
+
const instanceId = readNonEmptyString2(event.instanceId);
|
|
8659
8955
|
if (!instanceId) return;
|
|
8660
8956
|
const sourceInstance = components.instanceManager.getInstance(instanceId);
|
|
8661
8957
|
if (!sourceInstance || sourceInstance.category !== "cli") return;
|
|
8662
8958
|
const state = sourceInstance.getState();
|
|
8663
|
-
const workspace =
|
|
8959
|
+
const workspace = readNonEmptyString2(state.workspace);
|
|
8664
8960
|
if (!workspace) return;
|
|
8665
8961
|
const settings = state.settings && typeof state.settings === "object" ? state.settings : {};
|
|
8666
|
-
if (
|
|
8667
|
-
const meshIdFromRuntime =
|
|
8962
|
+
if (readNonEmptyString2(settings.meshCoordinatorFor)) return;
|
|
8963
|
+
const meshIdFromRuntime = readNonEmptyString2(settings.meshNodeFor);
|
|
8668
8964
|
const isMeshDelegate = Boolean(meshIdFromRuntime || settings.launchedByCoordinator);
|
|
8669
8965
|
if (!isMeshDelegate) return;
|
|
8670
8966
|
const mesh = meshIdFromRuntime ? getMeshWithCache(components, meshIdFromRuntime) : getMeshByRepo(workspace);
|
|
8671
|
-
const meshId = meshIdFromRuntime ||
|
|
8967
|
+
const meshId = meshIdFromRuntime || readNonEmptyString2(mesh?.id);
|
|
8672
8968
|
if (!meshId) return;
|
|
8673
8969
|
const targetNode = mesh?.nodes?.find((n) => n.workspace === workspace);
|
|
8674
|
-
const runtimeNodeId =
|
|
8970
|
+
const runtimeNodeId = readNonEmptyString2(settings.meshNodeId);
|
|
8675
8971
|
const resolvedNodeId = targetNode?.id || runtimeNodeId;
|
|
8676
8972
|
const nodeLabel = targetNode ? `Node '${targetNode.id}'` : runtimeNodeId ? `Node '${runtimeNodeId}'` : `Agent at ${workspace}`;
|
|
8677
8973
|
injectMeshSystemMessage(components, {
|
|
@@ -20482,7 +20778,9 @@ function resolveCliSpawnPlan(options) {
|
|
|
20482
20778
|
const configuredCommand = typeof runtimeSettings.executablePath === "string" && runtimeSettings.executablePath.trim() ? runtimeSettings.executablePath.trim() : spawnConfig.command;
|
|
20483
20779
|
const binaryPath = findBinary(configuredCommand);
|
|
20484
20780
|
const isWin = os13.platform() === "win32";
|
|
20485
|
-
const allArgs = [...spawnConfig.args, ...extraArgs]
|
|
20781
|
+
const allArgs = [...spawnConfig.args, ...extraArgs].map(
|
|
20782
|
+
(arg) => typeof arg === "string" ? arg.replace(/\{\{workingDir\}\}/g, workingDir) : arg
|
|
20783
|
+
);
|
|
20486
20784
|
let shellCmd;
|
|
20487
20785
|
let shellArgs;
|
|
20488
20786
|
const useShellUnix = !isWin && (!!spawnConfig.shell || !path16.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
|
|
@@ -23256,6 +23554,44 @@ var init_cli_provider_instance = __esm({
|
|
|
23256
23554
|
const content = lastVisible ? flattenContent(lastVisible.content).trim() : "";
|
|
23257
23555
|
return role === "assistant" && !!content;
|
|
23258
23556
|
}
|
|
23557
|
+
buildCompletedFinalizationDiagnostic(args) {
|
|
23558
|
+
let parsed = null;
|
|
23559
|
+
let parseError;
|
|
23560
|
+
try {
|
|
23561
|
+
parsed = this.adapter.getScriptParsedStatus();
|
|
23562
|
+
} catch (error48) {
|
|
23563
|
+
parseError = error48?.message || String(error48);
|
|
23564
|
+
}
|
|
23565
|
+
const visibleMessages = (Array.isArray(parsed?.messages) ? parsed.messages : []).filter((message) => isUserFacingChatMessage(message));
|
|
23566
|
+
const lastVisible = visibleMessages[visibleMessages.length - 1];
|
|
23567
|
+
const lastVisibleRole = typeof lastVisible?.role === "string" ? lastVisible.role.trim().toLowerCase() : null;
|
|
23568
|
+
const lastVisibleKind = typeof lastVisible?.kind === "string" ? lastVisible.kind : null;
|
|
23569
|
+
const lastVisibleContentLength = lastVisible ? flattenContent(lastVisible.content).trim().length : 0;
|
|
23570
|
+
return {
|
|
23571
|
+
providerType: this.type,
|
|
23572
|
+
sessionId: this.instanceId,
|
|
23573
|
+
providerSessionId: this.providerSessionId || null,
|
|
23574
|
+
workspace: this.workingDir,
|
|
23575
|
+
blockReason: args.blockReason,
|
|
23576
|
+
emittedAfterFinalizationTimeout: args.emittedAfterFinalizationTimeout,
|
|
23577
|
+
waitedMs: args.waitedMs,
|
|
23578
|
+
maxWaitMs: COMPLETED_FINALIZATION_MAX_WAIT_MS,
|
|
23579
|
+
adapterStatus: typeof args.latestStatus?.status === "string" ? args.latestStatus.status : null,
|
|
23580
|
+
latestVisibleStatus: args.latestVisibleStatus,
|
|
23581
|
+
parsedStatus: typeof parsed?.status === "string" ? parsed.status : parseError ? "parse_error" : "unknown",
|
|
23582
|
+
parseError: parseError || void 0,
|
|
23583
|
+
finalAssistantPresent: this.completionHasFinalAssistantMessage(parsed?.messages),
|
|
23584
|
+
visibleMessageCount: visibleMessages.length,
|
|
23585
|
+
lastVisibleRole,
|
|
23586
|
+
lastVisibleKind,
|
|
23587
|
+
lastVisibleContentLength,
|
|
23588
|
+
pendingStartedAt: this.generatingStartedAt || null,
|
|
23589
|
+
pendingFirstObservedAt: args.pending.firstObservedAt,
|
|
23590
|
+
pendingTimestamp: args.pending.timestamp,
|
|
23591
|
+
pendingDurationSec: args.pending.duration,
|
|
23592
|
+
previousBlockReason: args.pending.loggedBlockReason || null
|
|
23593
|
+
};
|
|
23594
|
+
}
|
|
23259
23595
|
hasAdapterPendingResponse() {
|
|
23260
23596
|
const adapterAny = this.adapter;
|
|
23261
23597
|
if (adapterAny?.isWaitingForResponse === true) return true;
|
|
@@ -23328,7 +23664,23 @@ var init_cli_provider_instance = __esm({
|
|
|
23328
23664
|
this.scheduleCompletedDebounceFlush(COMPLETED_FINALIZATION_RETRY_MS);
|
|
23329
23665
|
return;
|
|
23330
23666
|
}
|
|
23331
|
-
|
|
23667
|
+
const completionDiagnostic = this.buildCompletedFinalizationDiagnostic({
|
|
23668
|
+
blockReason,
|
|
23669
|
+
latestStatus,
|
|
23670
|
+
latestVisibleStatus,
|
|
23671
|
+
waitedMs,
|
|
23672
|
+
pending,
|
|
23673
|
+
emittedAfterFinalizationTimeout: true
|
|
23674
|
+
});
|
|
23675
|
+
LOG.warn("CLI", `[${this.type}] emitting completed event after ${waitedMs}ms without finalized assistant turn (${blockReason})`);
|
|
23676
|
+
this.pushEvent({
|
|
23677
|
+
event: "agent:generating_completed",
|
|
23678
|
+
chatTitle: pending.chatTitle,
|
|
23679
|
+
duration: pending.duration,
|
|
23680
|
+
timestamp: pending.timestamp,
|
|
23681
|
+
finalSummary: extractFinalSummaryFromMessages(this.adapter?.getScriptParsedStatus()?.messages),
|
|
23682
|
+
completionDiagnostic
|
|
23683
|
+
});
|
|
23332
23684
|
this.completedDebouncePending = null;
|
|
23333
23685
|
this.completedDebounceTimer = null;
|
|
23334
23686
|
this.generatingStartedAt = 0;
|
|
@@ -47779,6 +48131,9 @@ function reconcileInlineMeshCache(cached2, incoming) {
|
|
|
47779
48131
|
const cachedNodes = Array.isArray(cached2.nodes) ? cached2.nodes : [];
|
|
47780
48132
|
const incomingNodes = Array.isArray(incoming.nodes) ? incoming.nodes : [];
|
|
47781
48133
|
if (!cachedNodes.length || !incomingNodes.length) return { ...cached2, ...incoming };
|
|
48134
|
+
const cachedUpdatedAt = Date.parse(readStringValue(cached2.updatedAt, cached2.updated_at) || "");
|
|
48135
|
+
const incomingUpdatedAt = Date.parse(readStringValue(incoming.updatedAt, incoming.updated_at) || "");
|
|
48136
|
+
const preserveCachedMembership = Number.isFinite(cachedUpdatedAt) && (!Number.isFinite(incomingUpdatedAt) || cachedUpdatedAt > incomingUpdatedAt);
|
|
47782
48137
|
const cachedById = /* @__PURE__ */ new Map();
|
|
47783
48138
|
for (const node of cachedNodes) {
|
|
47784
48139
|
const nodeId = readInlineMeshNodeId(node);
|
|
@@ -47787,12 +48142,13 @@ function reconcileInlineMeshCache(cached2, incoming) {
|
|
|
47787
48142
|
const nodes = incomingNodes.map((incomingNode) => {
|
|
47788
48143
|
const nodeId = readInlineMeshNodeId(incomingNode);
|
|
47789
48144
|
const cachedNode = nodeId ? cachedById.get(nodeId) : void 0;
|
|
48145
|
+
if (!cachedNode && preserveCachedMembership) return null;
|
|
47790
48146
|
if (!cachedNode) return incomingNode;
|
|
47791
48147
|
if (hasInlineMeshTransientNodeState(incomingNode)) {
|
|
47792
48148
|
return { ...cachedNode, ...incomingNode };
|
|
47793
48149
|
}
|
|
47794
48150
|
return { ...stripInlineMeshTransientNodeState(cachedNode), ...incomingNode };
|
|
47795
|
-
});
|
|
48151
|
+
}).filter(Boolean);
|
|
47796
48152
|
return {
|
|
47797
48153
|
...cached2,
|
|
47798
48154
|
...incoming,
|
|
@@ -59506,6 +59862,8 @@ __export(src_exports, {
|
|
|
59506
59862
|
buildChatTailDeliverySignature: () => buildChatTailDeliverySignature,
|
|
59507
59863
|
buildCoordinatorSystemPrompt: () => buildCoordinatorSystemPrompt,
|
|
59508
59864
|
buildMachineInfo: () => buildMachineInfo,
|
|
59865
|
+
buildMeshActiveWork: () => buildMeshActiveWork,
|
|
59866
|
+
buildMeshActiveWorkSummary: () => buildMeshActiveWorkSummary,
|
|
59509
59867
|
buildMeshHostRequiredFailure: () => buildMeshHostRequiredFailure,
|
|
59510
59868
|
buildMeshLedgerReconciliationEvidence: () => buildMeshLedgerReconciliationEvidence,
|
|
59511
59869
|
buildMeshLedgerReplicaEvidence: () => buildMeshLedgerReplicaEvidence,
|
|
@@ -59516,6 +59874,7 @@ __export(src_exports, {
|
|
|
59516
59874
|
buildSessionModalDeliverySignature: () => buildSessionModalDeliverySignature,
|
|
59517
59875
|
buildStatusSnapshot: () => buildStatusSnapshot,
|
|
59518
59876
|
buildSystemChatMessage: () => buildSystemChatMessage,
|
|
59877
|
+
buildTaskCompletionEvidence: () => buildTaskCompletionEvidence,
|
|
59519
59878
|
buildTerminalChatMessage: () => buildTerminalChatMessage,
|
|
59520
59879
|
buildThoughtChatMessage: () => buildThoughtChatMessage,
|
|
59521
59880
|
buildToolChatMessage: () => buildToolChatMessage,
|
|
@@ -59626,6 +59985,8 @@ __export(src_exports, {
|
|
|
59626
59985
|
normalizeInputEnvelope: () => normalizeInputEnvelope,
|
|
59627
59986
|
normalizeManagedStatus: () => normalizeManagedStatus,
|
|
59628
59987
|
normalizeMeshDaemonRole: () => normalizeMeshDaemonRole,
|
|
59988
|
+
normalizeMeshTaskMode: () => normalizeMeshTaskMode,
|
|
59989
|
+
normalizeMeshWorkerResult: () => normalizeMeshWorkerResult,
|
|
59629
59990
|
normalizeMessageParts: () => normalizeMessageParts,
|
|
59630
59991
|
normalizeRepoIdentity: () => normalizeRepoIdentity,
|
|
59631
59992
|
normalizeSessionModalFields: () => normalizeSessionModalFields,
|
|
@@ -59681,7 +60042,8 @@ __export(src_exports, {
|
|
|
59681
60042
|
updateSessionTaskStatus: () => updateSessionTaskStatus,
|
|
59682
60043
|
updateTaskStatus: () => updateTaskStatus,
|
|
59683
60044
|
upsertSavedProviderSession: () => upsertSavedProviderSession,
|
|
59684
|
-
validateMeshRefineConfig: () => validateMeshRefineConfig
|
|
60045
|
+
validateMeshRefineConfig: () => validateMeshRefineConfig,
|
|
60046
|
+
validateMeshTaskModeRequest: () => validateMeshTaskModeRequest
|
|
59685
60047
|
});
|
|
59686
60048
|
var init_src = __esm({
|
|
59687
60049
|
"../../oss/packages/daemon-core/src/index.ts"() {
|
|
@@ -59700,6 +60062,7 @@ var init_src = __esm({
|
|
|
59700
60062
|
init_mesh_fast_forward();
|
|
59701
60063
|
init_mesh_ledger_reconciliation();
|
|
59702
60064
|
init_mesh_work_queue();
|
|
60065
|
+
init_mesh_active_work();
|
|
59703
60066
|
init_mesh_host_ownership();
|
|
59704
60067
|
init_mesh_events();
|
|
59705
60068
|
init_p2p_relay_failure();
|
|
@@ -100517,7 +100880,7 @@ var init_adhdev_daemon = __esm({
|
|
|
100517
100880
|
init_version();
|
|
100518
100881
|
init_src();
|
|
100519
100882
|
init_runtime_defaults();
|
|
100520
|
-
pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.
|
|
100883
|
+
pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.59" });
|
|
100521
100884
|
AdhdevDaemon = class _AdhdevDaemon {
|
|
100522
100885
|
localHttpServer = null;
|
|
100523
100886
|
localWss = null;
|