adhdev 0.9.82-rc.32 → 0.9.82-rc.34

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 CHANGED
@@ -66813,6 +66813,13 @@ var init_daemon_mesh_manager = __esm({
66813
66813
  p2pFailure(message, command, targetDaemonId) {
66814
66814
  return new P2pRelayFailureError(message, { command, targetDaemonId });
66815
66815
  }
66816
+ logMeshCommandEvent(event, fields) {
66817
+ try {
66818
+ LOG.info("Mesh", `[MeshCommand] ${JSON.stringify({ event, ...fields })}`);
66819
+ } catch {
66820
+ LOG.info("Mesh", `[MeshCommand] ${event}`);
66821
+ }
66822
+ }
66816
66823
  updatePeerSnapshot(targetDaemonId, state, patch = {}) {
66817
66824
  const previous = this.peerSnapshots.get(targetDaemonId);
66818
66825
  const now = (/* @__PURE__ */ new Date()).toISOString();
@@ -66943,6 +66950,13 @@ var init_daemon_mesh_manager = __esm({
66943
66950
  const peer = this.peers.get(targetDaemonId);
66944
66951
  if (!peer || peer.state !== "connected" || !peer.dataChannel?.isOpen()) {
66945
66952
  LOG.warn("Mesh", `[Mesh] Cannot send result for ${requestId}, P2P not open with ${targetDaemonId.slice(0, 12)}`);
66953
+ this.logMeshCommandEvent("response_send_failed", {
66954
+ requestId,
66955
+ targetDaemonId,
66956
+ sentAt: (/* @__PURE__ */ new Date()).toISOString(),
66957
+ peerState: peer?.state ?? "missing",
66958
+ error: "P2P not open"
66959
+ });
66946
66960
  return;
66947
66961
  }
66948
66962
  try {
@@ -66953,8 +66967,22 @@ var init_daemon_mesh_manager = __esm({
66953
66967
  result,
66954
66968
  error: error48
66955
66969
  }));
66970
+ this.logMeshCommandEvent("response_sent", {
66971
+ requestId,
66972
+ targetDaemonId,
66973
+ sentAt: (/* @__PURE__ */ new Date()).toISOString(),
66974
+ peerState: peer.state,
66975
+ success: !error48
66976
+ });
66956
66977
  } catch (err) {
66957
66978
  LOG.warn("Mesh", `[Mesh] Failed to send command result: ${err.message}`);
66979
+ this.logMeshCommandEvent("response_send_failed", {
66980
+ requestId,
66981
+ targetDaemonId,
66982
+ sentAt: (/* @__PURE__ */ new Date()).toISOString(),
66983
+ peerState: peer.state,
66984
+ error: err?.message || "Failed to send command result"
66985
+ });
66958
66986
  }
66959
66987
  }
66960
66988
  /** Convenience: send a one-off mesh command without a rule. */
@@ -66986,9 +67014,21 @@ var init_daemon_mesh_manager = __esm({
66986
67014
  }
66987
67015
  return new Promise((resolve20, reject) => {
66988
67016
  const requestId = `req_${Date.now()}_${Math.random().toString(36).slice(2, 8)}`;
67017
+ const queuedAt = (/* @__PURE__ */ new Date()).toISOString();
66989
67018
  const timer = setTimeout(() => {
67019
+ const pending = this.pendingRequests.get(requestId);
66990
67020
  this.pendingRequests.delete(requestId);
67021
+ const timedOutAt = (/* @__PURE__ */ new Date()).toISOString();
66991
67022
  const message = `P2P DataChannel command '${command}' to ${targetDaemonId.slice(0, 12)} timed out after 30s`;
67023
+ this.logMeshCommandEvent("timeout", {
67024
+ requestId,
67025
+ command,
67026
+ targetDaemonId,
67027
+ queuedAt: pending?.queuedAt ?? queuedAt,
67028
+ sentAt: pending?.sentAt,
67029
+ timedOutAt,
67030
+ peerState: peer?.state
67031
+ });
66992
67032
  this.invalidatePeer(targetDaemonId, message, { rejectPending: true, excludeRequestId: requestId });
66993
67033
  reject(this.p2pFailure(message, command, targetDaemonId));
66994
67034
  }, 3e4);
@@ -67005,7 +67045,8 @@ var init_daemon_mesh_manager = __esm({
67005
67045
  },
67006
67046
  timer,
67007
67047
  targetDaemonId,
67008
- command
67048
+ command,
67049
+ queuedAt
67009
67050
  });
67010
67051
  const payload = {
67011
67052
  type: "mesh_command",
@@ -67014,18 +67055,47 @@ var init_daemon_mesh_manager = __esm({
67014
67055
  args
67015
67056
  };
67016
67057
  if (peer.state === "connected" && peer.dataChannel?.isOpen()) {
67058
+ const sentAt = (/* @__PURE__ */ new Date()).toISOString();
67059
+ const pending = this.pendingRequests.get(requestId);
67060
+ if (pending) pending.sentAt = sentAt;
67017
67061
  LOG.info("Mesh", `[Mesh] Sending '${command}' via P2P DataChannel to ${targetDaemonId.slice(0, 12)}`);
67062
+ this.logMeshCommandEvent("sent", {
67063
+ requestId,
67064
+ command,
67065
+ targetDaemonId,
67066
+ queuedAt,
67067
+ sentAt,
67068
+ peerState: peer.state,
67069
+ transport: peer.isRelay === true ? "relay" : peer.isRelay === false ? "direct" : "unknown"
67070
+ });
67018
67071
  try {
67019
67072
  peer.dataChannel.sendMessage(JSON.stringify(payload));
67020
67073
  } catch (err) {
67021
67074
  const req = this.pendingRequests.get(requestId);
67022
67075
  const message = err?.message || "P2P DataChannel send failed";
67076
+ this.logMeshCommandEvent("send_failed", {
67077
+ requestId,
67078
+ command,
67079
+ targetDaemonId,
67080
+ queuedAt,
67081
+ sentAt,
67082
+ failedAt: (/* @__PURE__ */ new Date()).toISOString(),
67083
+ error: message
67084
+ });
67023
67085
  this.invalidatePeer(targetDaemonId, message, { rejectPending: true, excludeRequestId: requestId });
67024
67086
  if (req) req.reject(this.p2pFailure(message, command, targetDaemonId));
67025
67087
  }
67026
67088
  return;
67027
67089
  }
67028
67090
  LOG.info("Mesh", `[Mesh] Queuing '${command}' for ${targetDaemonId.slice(0, 12)} (state: ${peer.state})`);
67091
+ this.logMeshCommandEvent("queued", {
67092
+ requestId,
67093
+ command,
67094
+ targetDaemonId,
67095
+ queuedAt,
67096
+ peerState: peer.state,
67097
+ transport: peer.isRelay === true ? "relay" : peer.isRelay === false ? "direct" : "unknown"
67098
+ });
67029
67099
  if (!peer.commandQueue) {
67030
67100
  peer.commandQueue = [];
67031
67101
  }
@@ -67033,6 +67103,7 @@ var init_daemon_mesh_manager = __esm({
67033
67103
  command,
67034
67104
  args,
67035
67105
  requestId,
67106
+ queuedAt,
67036
67107
  reject: (err) => {
67037
67108
  const req = this.pendingRequests.get(requestId);
67038
67109
  if (req) req.reject(err);
@@ -67187,7 +67258,20 @@ var init_daemon_mesh_manager = __esm({
67187
67258
  entry.commandQueue = [];
67188
67259
  for (const item of queue) {
67189
67260
  try {
67261
+ const sentAt = (/* @__PURE__ */ new Date()).toISOString();
67262
+ const pending = this.pendingRequests.get(item.requestId);
67263
+ if (pending) pending.sentAt = sentAt;
67190
67264
  LOG.info("Mesh", `[Mesh] Flushing queued '${item.command}' to ${targetDaemonId.slice(0, 12)}`);
67265
+ this.logMeshCommandEvent("sent", {
67266
+ requestId: item.requestId,
67267
+ command: item.command,
67268
+ targetDaemonId,
67269
+ queuedAt: item.queuedAt,
67270
+ sentAt,
67271
+ peerState: entry.state,
67272
+ transport: entry.isRelay === true ? "relay" : entry.isRelay === false ? "direct" : "unknown",
67273
+ flushed: true
67274
+ });
67191
67275
  dc.sendMessage(JSON.stringify({
67192
67276
  type: "mesh_command",
67193
67277
  requestId: item.requestId,
@@ -67195,6 +67279,14 @@ var init_daemon_mesh_manager = __esm({
67195
67279
  args: item.args
67196
67280
  }));
67197
67281
  } catch (err) {
67282
+ this.logMeshCommandEvent("send_failed", {
67283
+ requestId: item.requestId,
67284
+ command: item.command,
67285
+ targetDaemonId,
67286
+ queuedAt: item.queuedAt,
67287
+ failedAt: (/* @__PURE__ */ new Date()).toISOString(),
67288
+ error: err?.message || "P2P DataChannel send failed while flushing command queue"
67289
+ });
67198
67290
  item.reject(this.p2pFailure(err?.message || "P2P DataChannel send failed while flushing command queue", item.command, targetDaemonId));
67199
67291
  }
67200
67292
  }
@@ -67209,6 +67301,12 @@ var init_daemon_mesh_manager = __esm({
67209
67301
  const str2 = typeof msg === "string" ? msg : msg.toString("utf8");
67210
67302
  const data = JSON.parse(str2);
67211
67303
  if (data.type === "mesh_command" && data.command) {
67304
+ this.logMeshCommandEvent("incoming", {
67305
+ requestId: data.requestId,
67306
+ command: data.command,
67307
+ senderDaemonId: targetDaemonId,
67308
+ receivedAt: (/* @__PURE__ */ new Date()).toISOString()
67309
+ });
67212
67310
  if (this.commandCallback) {
67213
67311
  this.commandCallback(targetDaemonId, data.command, data.args, data.requestId).catch((e) => {
67214
67312
  LOG.warn("Mesh", `[Mesh] Error handling incoming P2P command: ${e.message}`);
@@ -67217,11 +67315,27 @@ var init_daemon_mesh_manager = __esm({
67217
67315
  } else if (data.type === "mesh_command_result" && data.requestId) {
67218
67316
  const pending = this.pendingRequests.get(data.requestId);
67219
67317
  if (pending) {
67318
+ this.logMeshCommandEvent("response_received", {
67319
+ requestId: data.requestId,
67320
+ command: pending.command,
67321
+ targetDaemonId: pending.targetDaemonId,
67322
+ queuedAt: pending.queuedAt,
67323
+ sentAt: pending.sentAt,
67324
+ receivedAt: (/* @__PURE__ */ new Date()).toISOString(),
67325
+ success: data.success === true
67326
+ });
67220
67327
  if (data.success) {
67221
67328
  pending.resolve(data.result);
67222
67329
  } else {
67223
67330
  pending.reject(new Error(data.error || "P2P Command failed"));
67224
67331
  }
67332
+ } else {
67333
+ this.logMeshCommandEvent("response_orphan", {
67334
+ requestId: data.requestId,
67335
+ targetDaemonId,
67336
+ receivedAt: (/* @__PURE__ */ new Date()).toISOString(),
67337
+ success: data.success === true
67338
+ });
67225
67339
  }
67226
67340
  }
67227
67341
  } catch (e) {
@@ -67478,7 +67592,7 @@ var init_adhdev_daemon = __esm({
67478
67592
  init_version();
67479
67593
  init_src();
67480
67594
  init_runtime_defaults();
67481
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.32" });
67595
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.82-rc.34" });
67482
67596
  AdhdevDaemon = class _AdhdevDaemon {
67483
67597
  localHttpServer = null;
67484
67598
  localWss = null;