@adhdev/daemon-core 0.9.82-rc.61 → 0.9.82-rc.62
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/index.js +77 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -2
- package/dist/index.mjs.map +1 -1
- package/dist/mesh/mesh-events.d.ts +11 -0
- package/package.json +1 -1
- package/src/mesh/mesh-events.ts +81 -0
package/dist/index.mjs
CHANGED
|
@@ -2338,12 +2338,34 @@ function sweepExpiredRemoteIdleSessions() {
|
|
|
2338
2338
|
if (session.expiresAt <= now) remoteIdleSessions.delete(key);
|
|
2339
2339
|
}
|
|
2340
2340
|
}
|
|
2341
|
+
function readRefineJobId(event) {
|
|
2342
|
+
const metadata = readRecord(event.metadataEvent) || event;
|
|
2343
|
+
const result = readRecord(metadata.result);
|
|
2344
|
+
const refineJob = readRecord(result?.refineJob);
|
|
2345
|
+
return readNonEmptyString2(metadata.jobId) || readNonEmptyString2(refineJob?.jobId);
|
|
2346
|
+
}
|
|
2347
|
+
function buildRefineTerminalEventFingerprint(meshId, eventName, metadataEvent) {
|
|
2348
|
+
const jobId = readRefineJobId({ metadataEvent });
|
|
2349
|
+
return jobId && REFINE_TERMINAL_EVENTS.has(eventName) ? `${meshId}::${eventName}::${jobId}` : "";
|
|
2350
|
+
}
|
|
2351
|
+
function hasPendingRefineTerminalEventDuplicate(event) {
|
|
2352
|
+
if (!REFINE_TERMINAL_EVENTS.has(event.event)) return false;
|
|
2353
|
+
const jobId = readRefineJobId(event);
|
|
2354
|
+
if (!jobId) return false;
|
|
2355
|
+
return getPendingMeshCoordinatorEvents(event.meshId).some(
|
|
2356
|
+
(pending) => pending.event === event.event && readRefineJobId(pending) === jobId
|
|
2357
|
+
);
|
|
2358
|
+
}
|
|
2341
2359
|
function getPendingEventsPath(meshId) {
|
|
2342
2360
|
const safe = meshId.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
2343
2361
|
return join10(getLedgerDir(), `${safe}.pending-events.jsonl`);
|
|
2344
2362
|
}
|
|
2345
2363
|
function queuePendingMeshCoordinatorEvent(event) {
|
|
2346
2364
|
try {
|
|
2365
|
+
if (hasPendingRefineTerminalEventDuplicate(event)) {
|
|
2366
|
+
LOG.info("MeshEvents", `Suppressed duplicate pending ${event.event} for refine job ${readRefineJobId(event)}`);
|
|
2367
|
+
return true;
|
|
2368
|
+
}
|
|
2347
2369
|
appendFileSync3(getPendingEventsPath(event.meshId), JSON.stringify(event) + "\n", "utf-8");
|
|
2348
2370
|
return true;
|
|
2349
2371
|
} catch (e) {
|
|
@@ -2481,6 +2503,17 @@ function isDuplicateMeshCompletionEvent(args) {
|
|
|
2481
2503
|
recentCompletionFingerprints.set(fingerprint, now);
|
|
2482
2504
|
return false;
|
|
2483
2505
|
}
|
|
2506
|
+
function isDuplicateRefineTerminalEvent(meshId, eventName, metadataEvent) {
|
|
2507
|
+
const fingerprint = buildRefineTerminalEventFingerprint(meshId, eventName, metadataEvent);
|
|
2508
|
+
if (!fingerprint) return false;
|
|
2509
|
+
const now = Date.now();
|
|
2510
|
+
for (const [key, seenAt] of recentCompletionFingerprints.entries()) {
|
|
2511
|
+
if (now - seenAt > RECENT_COMPLETION_FINGERPRINT_TTL_MS) recentCompletionFingerprints.delete(key);
|
|
2512
|
+
}
|
|
2513
|
+
if (recentCompletionFingerprints.has(fingerprint)) return true;
|
|
2514
|
+
recentCompletionFingerprints.set(fingerprint, now);
|
|
2515
|
+
return false;
|
|
2516
|
+
}
|
|
2484
2517
|
function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType) {
|
|
2485
2518
|
const task = claimNextTask(meshId, nodeId, sessionId);
|
|
2486
2519
|
if (!task) {
|
|
@@ -2823,6 +2856,32 @@ Do NOT retry on this node. Consider reassigning to a different node or asking th
|
|
|
2823
2856
|
if (args.event === "monitor:long_generating") {
|
|
2824
2857
|
return `[System] ${args.nodeLabel} has been generating for a long time${metadata}. Use mesh_read_chat once for a status check, but do not poll repeatedly.`;
|
|
2825
2858
|
}
|
|
2859
|
+
if (args.event === "refine:accepted") {
|
|
2860
|
+
const jobId = readRefineJobId({ metadataEvent: args.metadataEvent });
|
|
2861
|
+
return `[System] Refinery accepted async job${jobId ? ` ${jobId}` : ""} for ${args.nodeLabel}. Completion/failure will be delivered as a terminal refine event; do not poll repeatedly.`;
|
|
2862
|
+
}
|
|
2863
|
+
if (args.event === "refine:completed") {
|
|
2864
|
+
const jobId = readRefineJobId({ metadataEvent: args.metadataEvent });
|
|
2865
|
+
const result = readRecord(args.metadataEvent.result);
|
|
2866
|
+
const validationSummary = readRecord(result?.validationSummary);
|
|
2867
|
+
const validationStatus = readNonEmptyString2(validationSummary?.status);
|
|
2868
|
+
const into = readNonEmptyString2(result?.into);
|
|
2869
|
+
const branch = readNonEmptyString2(result?.branch);
|
|
2870
|
+
const details = [
|
|
2871
|
+
jobId ? `job_id=${jobId}` : "",
|
|
2872
|
+
branch && into ? `${branch}\u2192${into}` : "",
|
|
2873
|
+
validationStatus ? `validation=${validationStatus}` : ""
|
|
2874
|
+
].filter(Boolean).join("; ");
|
|
2875
|
+
return `[System] Refinery async job for ${args.nodeLabel} completed successfully${details ? ` (${details})` : ""}. The worktree was merged and cleanup completed; continue from the updated mesh state.`;
|
|
2876
|
+
}
|
|
2877
|
+
if (args.event === "refine:failed") {
|
|
2878
|
+
const jobId = readRefineJobId({ metadataEvent: args.metadataEvent });
|
|
2879
|
+
const result = readRecord(args.metadataEvent.result);
|
|
2880
|
+
const code = readNonEmptyString2(result?.code);
|
|
2881
|
+
const error = readNonEmptyString2(result?.error);
|
|
2882
|
+
const details = [jobId ? `job_id=${jobId}` : "", code ? `code=${code}` : ""].filter(Boolean).join("; ");
|
|
2883
|
+
return `[System] Refinery async job for ${args.nodeLabel} failed${details ? ` (${details})` : ""}${error ? `: ${error}` : "."} Review the terminal refine event/ledger before retrying.`;
|
|
2884
|
+
}
|
|
2826
2885
|
return "";
|
|
2827
2886
|
}
|
|
2828
2887
|
function injectMeshSystemMessage(components, args) {
|
|
@@ -2842,6 +2901,10 @@ function injectMeshSystemMessage(components, args) {
|
|
|
2842
2901
|
LOG.info("MeshEvents", `Suppressed ${args.event} for intentionally cleanup-stopped session ${eventSessionId || "(unknown session)"}`);
|
|
2843
2902
|
return { success: true, forwarded: 0, suppressed: true, intentionalCleanupStop: true };
|
|
2844
2903
|
}
|
|
2904
|
+
if (isDuplicateRefineTerminalEvent(args.meshId, args.event, args.metadataEvent)) {
|
|
2905
|
+
LOG.info("MeshEvents", `Suppressed duplicate ${args.event} for refine job ${readRefineJobId({ metadataEvent: args.metadataEvent })}`);
|
|
2906
|
+
return { success: true, forwarded: 0, suppressed: true, duplicateRefineTerminalEvent: true };
|
|
2907
|
+
}
|
|
2845
2908
|
const eventTimestamp = readEventTimestamp(args.metadataEvent.timestamp);
|
|
2846
2909
|
if (args.event === "agent:generating_completed" && eventSessionId) {
|
|
2847
2910
|
const duplicateCompletion = isDuplicateMeshCompletionEvent({
|
|
@@ -3091,6 +3154,14 @@ function handleMeshForwardEvent(components, payload) {
|
|
|
3091
3154
|
providerType: readNonEmptyString2(payload.providerType),
|
|
3092
3155
|
providerSessionId: readNonEmptyString2(payload.providerSessionId),
|
|
3093
3156
|
finalSummary: readNonEmptyString2(payload.finalSummary) || readNonEmptyString2(payload.summary),
|
|
3157
|
+
jobId: readNonEmptyString2(payload.jobId),
|
|
3158
|
+
interactionId: readNonEmptyString2(payload.interactionId),
|
|
3159
|
+
status: readNonEmptyString2(payload.status),
|
|
3160
|
+
targetDaemonId: readNonEmptyString2(payload.targetDaemonId),
|
|
3161
|
+
startedAt: readNonEmptyString2(payload.startedAt),
|
|
3162
|
+
completedAt: readNonEmptyString2(payload.completedAt),
|
|
3163
|
+
retryOfJobId: readNonEmptyString2(payload.retryOfJobId),
|
|
3164
|
+
...payload.result && typeof payload.result === "object" && !Array.isArray(payload.result) ? { result: payload.result } : {},
|
|
3094
3165
|
...payload.timestamp !== void 0 ? { timestamp: payload.timestamp } : {},
|
|
3095
3166
|
intentional: payload.intentional === true,
|
|
3096
3167
|
intentionalStop: payload.intentionalStop === true,
|
|
@@ -3134,7 +3205,7 @@ function setupMeshEventForwarding(components) {
|
|
|
3134
3205
|
});
|
|
3135
3206
|
});
|
|
3136
3207
|
}
|
|
3137
|
-
var 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;
|
|
3208
|
+
var REMOTE_IDLE_SESSION_TTL_MS, remoteIdleSessions, REFINE_TERMINAL_EVENTS, MESH_COORDINATOR_EVENTS, EVENT_TO_LEDGER_KIND, INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS, RECENT_COMPLETION_FINGERPRINT_TTL_MS, recentCompletionFingerprints, autoLaunchInProgress, autoLaunchCooldownUntil, AUTO_LAUNCH_COOLDOWN_MS;
|
|
3138
3209
|
var init_mesh_events = __esm({
|
|
3139
3210
|
"src/mesh/mesh-events.ts"() {
|
|
3140
3211
|
"use strict";
|
|
@@ -3146,13 +3217,17 @@ var init_mesh_events = __esm({
|
|
|
3146
3217
|
init_mesh_work_queue();
|
|
3147
3218
|
REMOTE_IDLE_SESSION_TTL_MS = 5 * 60 * 1e3;
|
|
3148
3219
|
remoteIdleSessions = /* @__PURE__ */ new Map();
|
|
3220
|
+
REFINE_TERMINAL_EVENTS = /* @__PURE__ */ new Set(["refine:completed", "refine:failed"]);
|
|
3149
3221
|
MESH_COORDINATOR_EVENTS = /* @__PURE__ */ new Set([
|
|
3150
3222
|
"agent:generating_started",
|
|
3151
3223
|
"agent:generating_completed",
|
|
3152
3224
|
"agent:waiting_approval",
|
|
3153
3225
|
"agent:stopped",
|
|
3154
3226
|
"agent:ready",
|
|
3155
|
-
"monitor:long_generating"
|
|
3227
|
+
"monitor:long_generating",
|
|
3228
|
+
"refine:accepted",
|
|
3229
|
+
"refine:completed",
|
|
3230
|
+
"refine:failed"
|
|
3156
3231
|
]);
|
|
3157
3232
|
EVENT_TO_LEDGER_KIND = {
|
|
3158
3233
|
"agent:generating_completed": "task_completed",
|