adhdev 0.9.82-rc.24 → 0.9.82-rc.26

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 CHANGED
@@ -3964,18 +3964,20 @@ function requeueTask(meshId, taskId, opts) {
3964
3964
  return entry;
3965
3965
  });
3966
3966
  }
3967
- function updateSessionTaskStatus(meshId, sessionId, status) {
3967
+ function updateSessionTaskStatus(meshId, sessionId, status, opts) {
3968
3968
  return withQueueLock(meshId, () => {
3969
3969
  const queue = readQueue(meshId);
3970
+ const occurredAtTime = opts?.occurredAt ? new Date(opts.occurredAt).getTime() : Number.NaN;
3971
+ const hasOccurredAt = Number.isFinite(occurredAtTime);
3970
3972
  let bestIdx = -1;
3971
3973
  let bestTime = 0;
3972
3974
  for (let i = queue.length - 1; i >= 0; i--) {
3973
- if (queue[i].assignedSessionId === sessionId && queue[i].status === "assigned") {
3974
- const time3 = new Date(queue[i].dispatchTimestamp || queue[i].updatedAt).getTime();
3975
- if (time3 > bestTime) {
3976
- bestTime = time3;
3977
- bestIdx = i;
3978
- }
3975
+ if (queue[i].assignedSessionId !== sessionId || queue[i].status !== "assigned") continue;
3976
+ const time3 = new Date(queue[i].dispatchTimestamp || queue[i].updatedAt).getTime();
3977
+ if (hasOccurredAt && Number.isFinite(time3) && time3 > occurredAtTime) continue;
3978
+ if (time3 > bestTime) {
3979
+ bestTime = time3;
3980
+ bestIdx = i;
3979
3981
  }
3980
3982
  }
3981
3983
  if (bestIdx === -1) return null;
@@ -4501,6 +4503,38 @@ function shouldSuppressIntentionalCleanupStop(args) {
4501
4503
  if (isIntentionalCleanupStopMetadata(args.metadataEvent)) return true;
4502
4504
  return hasRecentIntentionalCleanupStop(args.meshId, args.sessionId, args.nodeId);
4503
4505
  }
4506
+ function readEventTimestamp(value) {
4507
+ if (typeof value === "number" && Number.isFinite(value)) return value;
4508
+ if (typeof value === "string" && value.trim()) {
4509
+ const numeric = Number(value);
4510
+ if (Number.isFinite(numeric)) return numeric;
4511
+ const parsed = Date.parse(value);
4512
+ if (Number.isFinite(parsed)) return parsed;
4513
+ }
4514
+ return null;
4515
+ }
4516
+ function buildMeshCompletionFingerprint(args) {
4517
+ const timestampPart = Number.isFinite(args.timestamp) ? String(args.timestamp) : readNonEmptyString(args.finalSummary).slice(0, 200);
4518
+ return [
4519
+ args.meshId,
4520
+ args.event,
4521
+ args.sessionId,
4522
+ args.providerType || "",
4523
+ args.providerSessionId || "",
4524
+ timestampPart
4525
+ ].join("::");
4526
+ }
4527
+ function isDuplicateMeshCompletionEvent(args) {
4528
+ const fingerprint = buildMeshCompletionFingerprint(args);
4529
+ if (!fingerprint) return false;
4530
+ const now = Date.now();
4531
+ for (const [key, seenAt] of recentCompletionFingerprints.entries()) {
4532
+ if (now - seenAt > RECENT_COMPLETION_FINGERPRINT_TTL_MS) recentCompletionFingerprints.delete(key);
4533
+ }
4534
+ if (recentCompletionFingerprints.has(fingerprint)) return true;
4535
+ recentCompletionFingerprints.set(fingerprint, now);
4536
+ return false;
4537
+ }
4504
4538
  function tryAssignQueueTask(components, meshId, nodeId, sessionId, providerType) {
4505
4539
  const task = claimNextTask(meshId, nodeId, sessionId);
4506
4540
  if (!task) {
@@ -4862,13 +4896,31 @@ function injectMeshSystemMessage(components, args) {
4862
4896
  LOG.info("MeshEvents", `Suppressed ${args.event} for intentionally cleanup-stopped session ${eventSessionId || "(unknown session)"}`);
4863
4897
  return { success: true, forwarded: 0, suppressed: true, intentionalCleanupStop: true };
4864
4898
  }
4899
+ const eventTimestamp = readEventTimestamp(args.metadataEvent.timestamp);
4900
+ if (args.event === "agent:generating_completed" && eventSessionId) {
4901
+ const duplicateCompletion = isDuplicateMeshCompletionEvent({
4902
+ meshId: args.meshId,
4903
+ event: args.event,
4904
+ sessionId: eventSessionId,
4905
+ providerType: readNonEmptyString(args.metadataEvent.providerType) || void 0,
4906
+ providerSessionId: readNonEmptyString(args.metadataEvent.providerSessionId) || void 0,
4907
+ timestamp: eventTimestamp,
4908
+ finalSummary: readNonEmptyString(args.metadataEvent.finalSummary) || void 0
4909
+ });
4910
+ if (duplicateCompletion) {
4911
+ LOG.info("MeshEvents", `Suppressed duplicate completion for mesh ${args.meshId} session ${eventSessionId}`);
4912
+ return { success: true, forwarded: 0, suppressed: true, duplicateCompletion: true };
4913
+ }
4914
+ }
4865
4915
  let completedTaskForLedger = null;
4866
4916
  if (args.event === "agent:generating_completed") {
4867
4917
  const sessionId = resolveEventSessionId(args.metadataEvent, args.sourceInstanceId);
4868
4918
  const nodeId = readNonEmptyString(args.nodeId) || readNonEmptyString(args.metadataEvent.meshNodeId);
4869
4919
  const providerType = readNonEmptyString(args.metadataEvent.providerType);
4870
4920
  if (sessionId) {
4871
- const completedTask = updateSessionTaskStatus(args.meshId, sessionId, "completed");
4921
+ const completedTask = updateSessionTaskStatus(args.meshId, sessionId, "completed", {
4922
+ occurredAt: eventTimestamp !== null ? new Date(eventTimestamp).toISOString() : void 0
4923
+ });
4872
4924
  completedTaskForLedger = completedTask ? { id: completedTask.id } : null;
4873
4925
  if (nodeId && providerType) {
4874
4926
  setImmediate(() => {
@@ -5082,6 +5134,7 @@ function handleMeshForwardEvent(components, payload) {
5082
5134
  providerType: readNonEmptyString(payload.providerType),
5083
5135
  providerSessionId: readNonEmptyString(payload.providerSessionId),
5084
5136
  finalSummary: readNonEmptyString(payload.finalSummary) || readNonEmptyString(payload.summary),
5137
+ ...payload.timestamp !== void 0 ? { timestamp: payload.timestamp } : {},
5085
5138
  intentional: payload.intentional === true,
5086
5139
  intentionalStop: payload.intentionalStop === true,
5087
5140
  operatorCleanup: payload.operatorCleanup === true,
@@ -5124,7 +5177,7 @@ function setupMeshEventForwarding(components) {
5124
5177
  });
5125
5178
  });
5126
5179
  }
5127
- var import_fs6, import_path5, REMOTE_IDLE_SESSION_TTL_MS, remoteIdleSessions, MESH_COORDINATOR_EVENTS, EVENT_TO_LEDGER_KIND, INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS, autoLaunchInProgress, autoLaunchCooldownUntil, AUTO_LAUNCH_COOLDOWN_MS;
5180
+ var import_fs6, import_path5, REMOTE_IDLE_SESSION_TTL_MS, remoteIdleSessions, MESH_COORDINATOR_EVENTS, EVENT_TO_LEDGER_KIND, INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS, RECENT_COMPLETION_FINGERPRINT_TTL_MS, recentCompletionFingerprints, autoLaunchInProgress, autoLaunchCooldownUntil, AUTO_LAUNCH_COOLDOWN_MS;
5128
5181
  var init_mesh_events = __esm({
5129
5182
  "../../oss/packages/daemon-core/src/mesh/mesh-events.ts"() {
5130
5183
  "use strict";
@@ -5153,6 +5206,8 @@ var init_mesh_events = __esm({
5153
5206
  "monitor:long_generating": "task_stalled"
5154
5207
  };
5155
5208
  INTENTIONAL_CLEANUP_STOP_SUPPRESSION_MS = 30 * 60 * 1e3;
5209
+ RECENT_COMPLETION_FINGERPRINT_TTL_MS = 10 * 60 * 1e3;
5210
+ recentCompletionFingerprints = /* @__PURE__ */ new Map();
5156
5211
  autoLaunchInProgress = /* @__PURE__ */ new Set();
5157
5212
  autoLaunchCooldownUntil = /* @__PURE__ */ new Map();
5158
5213
  AUTO_LAUNCH_COOLDOWN_MS = 5e3;
@@ -46603,49 +46658,7 @@ function readGitSubmodules(value) {
46603
46658
  }).filter((entry) => entry !== null);
46604
46659
  return submodules.length > 0 ? submodules : void 0;
46605
46660
  }
46606
- function buildCachedInlineMeshGitStatus(node) {
46607
- const cachedStatus = readObjectRecord(node?.cachedStatus);
46608
- const cachedGit = readObjectRecord(cachedStatus.git);
46609
- if (Object.keys(cachedGit).length) {
46610
- const conflictFiles2 = Array.isArray(cachedGit.conflictFiles) ? cachedGit.conflictFiles.filter((value) => typeof value === "string") : [];
46611
- const conflictCount2 = readNumberValue(cachedGit.conflicts) ?? conflictFiles2.length;
46612
- const hasConflicts2 = readBooleanValue(cachedGit.hasConflicts) ?? conflictCount2 > 0;
46613
- const isGitRepo2 = readBooleanValue(cachedGit.isGitRepo);
46614
- if (isGitRepo2 !== void 0) {
46615
- const submodules2 = readGitSubmodules(cachedGit.submodules);
46616
- return {
46617
- workspace: readStringValue(cachedGit.workspace, node?.workspace) || "",
46618
- repoRoot: readStringValue(cachedGit.repoRoot, node?.repoRoot, node?.workspace) || null,
46619
- isGitRepo: isGitRepo2,
46620
- branch: readStringValue(cachedGit.branch) ?? null,
46621
- headCommit: readStringValue(cachedGit.headCommit) ?? null,
46622
- headMessage: readStringValue(cachedGit.headMessage) ?? null,
46623
- upstream: readStringValue(cachedGit.upstream) ?? null,
46624
- ahead: readNumberValue(cachedGit.ahead) ?? 0,
46625
- behind: readNumberValue(cachedGit.behind) ?? 0,
46626
- staged: readNumberValue(cachedGit.staged) ?? 0,
46627
- modified: readNumberValue(cachedGit.modified) ?? 0,
46628
- untracked: readNumberValue(cachedGit.untracked) ?? 0,
46629
- deleted: readNumberValue(cachedGit.deleted) ?? 0,
46630
- renamed: readNumberValue(cachedGit.renamed) ?? 0,
46631
- hasConflicts: hasConflicts2,
46632
- conflictFiles: conflictFiles2,
46633
- stashCount: readNumberValue(cachedGit.stashCount) ?? 0,
46634
- lastCheckedAt: readNumberValue(cachedGit.lastCheckedAt) ?? Date.now(),
46635
- ...submodules2 ? { submodules: submodules2 } : {}
46636
- };
46637
- }
46638
- }
46639
- const rawGit = readObjectRecord(node?.lastGit ?? node?.last_git);
46640
- const gitResult = readObjectRecord(rawGit.result);
46641
- const directStatus = readObjectRecord(rawGit.status);
46642
- const nestedStatus = readObjectRecord(gitResult.status);
46643
- const rawProbe = readObjectRecord(node?.lastProbe ?? node?.last_probe);
46644
- const probeGit = readObjectRecord(rawProbe.git);
46645
- const probeGitResult = readObjectRecord(probeGit.result);
46646
- const probeDirectStatus = readObjectRecord(probeGit.status);
46647
- const probeNestedStatus = readObjectRecord(probeGitResult.status);
46648
- const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
46661
+ function normalizeInlineMeshGitStatus(status, node, options) {
46649
46662
  const isGitRepo = readBooleanValue(status.isGitRepo);
46650
46663
  if (!Object.keys(status).length || isGitRepo === void 0) return void 0;
46651
46664
  const conflictFiles = Array.isArray(status.conflictFiles) ? status.conflictFiles.filter((value) => typeof value === "string") : [];
@@ -46670,10 +46683,31 @@ function buildCachedInlineMeshGitStatus(node) {
46670
46683
  hasConflicts,
46671
46684
  conflictFiles,
46672
46685
  stashCount: readNumberValue(status.stashCount) ?? 0,
46673
- lastCheckedAt: Date.now(),
46686
+ lastCheckedAt: options?.lastCheckedAt ?? readNumberValue(status.lastCheckedAt) ?? Date.now(),
46674
46687
  ...submodules ? { submodules } : {}
46675
46688
  };
46676
46689
  }
46690
+ function buildInlineMeshTransitGitStatus(node) {
46691
+ const rawGit = readObjectRecord(node?.lastGit ?? node?.last_git);
46692
+ const gitResult = readObjectRecord(rawGit.result);
46693
+ const directStatus = readObjectRecord(rawGit.status);
46694
+ const nestedStatus = readObjectRecord(gitResult.status);
46695
+ const rawProbe = readObjectRecord(node?.lastProbe ?? node?.last_probe);
46696
+ const probeGit = readObjectRecord(rawProbe.git);
46697
+ const probeGitResult = readObjectRecord(probeGit.result);
46698
+ const probeDirectStatus = readObjectRecord(probeGit.status);
46699
+ const probeNestedStatus = readObjectRecord(probeGitResult.status);
46700
+ const status = Object.keys(directStatus).length ? directStatus : Object.keys(nestedStatus).length ? nestedStatus : Object.keys(probeDirectStatus).length ? probeDirectStatus : Object.keys(probeNestedStatus).length ? probeNestedStatus : {};
46701
+ return normalizeInlineMeshGitStatus(status, node, { lastCheckedAt: Date.now() });
46702
+ }
46703
+ function buildCachedInlineMeshGitStatus(node) {
46704
+ const liveGit = buildInlineMeshTransitGitStatus(node);
46705
+ if (liveGit) return liveGit;
46706
+ const cachedStatus = readObjectRecord(node?.cachedStatus);
46707
+ const cachedGit = readObjectRecord(cachedStatus.git);
46708
+ if (!Object.keys(cachedGit).length) return void 0;
46709
+ return normalizeInlineMeshGitStatus(cachedGit, node);
46710
+ }
46677
46711
  function shouldDiscardCachedInlineMeshStatus(node) {
46678
46712
  const cachedStatus = readObjectRecord(node?.cachedStatus);
46679
46713
  if (!Object.keys(cachedStatus).length) return false;
@@ -46902,9 +46936,10 @@ function collectLiveMeshSessionRecords(args) {
46902
46936
  }
46903
46937
  function applyCachedInlineMeshNodeStatus(status, node) {
46904
46938
  const cachedStatus = readObjectRecord(node?.cachedStatus);
46905
- const git = buildCachedInlineMeshGitStatus(node);
46906
- const error48 = readStringValue(cachedStatus.error, node?.error);
46907
- const health = readStringValue(cachedStatus.health, node?.health);
46939
+ const liveGit = buildInlineMeshTransitGitStatus(node);
46940
+ const git = liveGit ?? buildCachedInlineMeshGitStatus(node);
46941
+ const error48 = liveGit ? void 0 : readStringValue(cachedStatus.error, node?.error);
46942
+ const health = liveGit ? void 0 : readStringValue(cachedStatus.health, node?.health);
46908
46943
  const machineStatus = readStringValue(cachedStatus.machineStatus, node?.machineStatus);
46909
46944
  const lastSeenAt = toIsoTimestamp(cachedStatus.lastSeenAt ?? cachedStatus.last_seen_at ?? node?.lastSeenAt ?? node?.last_seen_at);
46910
46945
  const updatedAt = toIsoTimestamp(cachedStatus.updatedAt ?? cachedStatus.updated_at ?? node?.updatedAt ?? node?.updated_at);
@@ -98410,7 +98445,7 @@ var init_adhdev_daemon = __esm({
98410
98445
  init_version();
98411
98446
  init_src();
98412
98447
  init_runtime_defaults();
98413
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.24" });
98448
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.26" });
98414
98449
  AdhdevDaemon = class _AdhdevDaemon {
98415
98450
  localHttpServer = null;
98416
98451
  localWss = null;
@@ -99304,6 +99339,7 @@ ${err?.stack || ""}`);
99304
99339
  const meshId = this.readMeshString(settings.meshNodeFor);
99305
99340
  const coordinatorDaemonId = this.readMeshString(settings.meshCoordinatorDaemonId);
99306
99341
  if (!meshId || !coordinatorDaemonId) return;
99342
+ const relayTimestamp = typeof event.timestamp === "number" && Number.isFinite(event.timestamp) ? event.timestamp : this.readMeshString(event.timestamp) || void 0;
99307
99343
  const payload = {
99308
99344
  event: this.readMeshString(event.event),
99309
99345
  meshId,
@@ -99312,7 +99348,8 @@ ${err?.stack || ""}`);
99312
99348
  targetSessionId: this.readMeshString(event.targetSessionId) || instanceId,
99313
99349
  providerType: this.readMeshString(event.providerType),
99314
99350
  providerSessionId: this.readMeshString(event.providerSessionId),
99315
- finalSummary: this.readMeshString(event.finalSummary) || this.readMeshString(event.summary)
99351
+ finalSummary: this.readMeshString(event.finalSummary) || this.readMeshString(event.summary),
99352
+ ...relayTimestamp !== void 0 ? { timestamp: relayTimestamp } : {}
99316
99353
  };
99317
99354
  if (coordinatorDaemonId === localDaemonId) {
99318
99355
  try {
@@ -99338,7 +99375,8 @@ ${err?.stack || ""}`);
99338
99375
  providerType: payload.providerType,
99339
99376
  providerSessionId: payload.providerSessionId,
99340
99377
  finalSummary: payload.finalSummary,
99341
- workspace: payload.workspace
99378
+ workspace: payload.workspace,
99379
+ ...payload.timestamp !== void 0 ? { timestamp: payload.timestamp } : {}
99342
99380
  },
99343
99381
  queuedAt: Date.now()
99344
99382
  });