@delt/claude-alarm 0.8.2 → 0.9.0

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
@@ -41,6 +41,12 @@ var WS_PATH_DASHBOARD = "/ws/dashboard";
41
41
  var CHANNEL_SERVER_NAME = "claude-alarm";
42
42
  var CHANNEL_SERVER_VERSION = "0.1.0";
43
43
 
44
+ // src/shared/peer-name.ts
45
+ var SAFE_PEER_NAME = /^[^\u0000-\u001f\u007f"\\[\]]{1,128}$/;
46
+ function isValidPeerName(name) {
47
+ return typeof name === "string" && name.trim() !== "" && SAFE_PEER_NAME.test(name);
48
+ }
49
+
44
50
  // src/hub/session-manager.ts
45
51
  var SessionManager = class {
46
52
  sessions = /* @__PURE__ */ new Map();
@@ -64,7 +70,7 @@ var SessionManager = class {
64
70
  } else {
65
71
  session.displayName = baseName;
66
72
  }
67
- this.sessions.set(session.id, { ...session });
73
+ this.sessions.set(session.id, { ...session, peerName: isValidPeerName(session.peerName) ? session.peerName : void 0 });
68
74
  }
69
75
  unregister(sessionId) {
70
76
  const session = this.sessions.get(sessionId);
@@ -79,6 +85,13 @@ var SessionManager = class {
79
85
  }
80
86
  return session;
81
87
  }
88
+ setPeerName(sessionId, peerName) {
89
+ const session = this.sessions.get(sessionId);
90
+ if (session) {
91
+ session.peerName = isValidPeerName(peerName) ? peerName : void 0;
92
+ }
93
+ return session;
94
+ }
82
95
  updateActivity(sessionId) {
83
96
  const session = this.sessions.get(sessionId);
84
97
  if (session) {
@@ -1065,7 +1078,7 @@ var HubServer = class {
1065
1078
  this.sessions.register(session);
1066
1079
  this.channelSockets.set(session.id, ws);
1067
1080
  if (isLocal) this.localChannels.add(session.id);
1068
- logger.info(`Session registered: ${session.id} (${session.name}, channel: ${session.channelEnabled ?? false})`);
1081
+ logger.info(`Session registered: ${session.id} (${session.name}, channel: ${session.channelEnabled ?? false}, peer: ${session.peerName ?? "-"})`);
1069
1082
  this.broadcastToDashboards({
1070
1083
  type: isReregister ? "session_updated" : "session_connected",
1071
1084
  session
@@ -1079,6 +1092,15 @@ var HubServer = class {
1079
1092
  }
1080
1093
  break;
1081
1094
  }
1095
+ case "peer_name": {
1096
+ if (this.channelSockets.get(msg.sessionId) !== ws) break;
1097
+ const updated = this.sessions.setPeerName(msg.sessionId, msg.peerName);
1098
+ if (updated) {
1099
+ logger.info(`Peer name for ${msg.sessionId}: ${msg.peerName ?? "-"}`);
1100
+ this.broadcastToDashboards({ type: "session_updated", session: updated });
1101
+ }
1102
+ break;
1103
+ }
1082
1104
  case "notify": {
1083
1105
  this.sessions.updateActivity(msg.sessionId);
1084
1106
  const notifySession = this.sessions.get(msg.sessionId);
@@ -1445,12 +1467,13 @@ if (process.argv[1] && (process.argv[1].endsWith("hub/server.js") || process.arg
1445
1467
  // src/channel/hub-client.ts
1446
1468
  import WebSocket2 from "ws";
1447
1469
  var HubClient = class {
1448
- constructor(sessionId, sessionName, hubHost = DEFAULT_HUB_HOST, hubPort = DEFAULT_HUB_PORT, token) {
1470
+ constructor(sessionId, sessionName, hubHost = DEFAULT_HUB_HOST, hubPort = DEFAULT_HUB_PORT, token, getPeerName = () => void 0) {
1449
1471
  this.sessionId = sessionId;
1450
1472
  this.sessionName = sessionName;
1451
1473
  this.hubHost = hubHost;
1452
1474
  this.hubPort = hubPort;
1453
1475
  this.token = token;
1476
+ this.getPeerName = getPeerName;
1454
1477
  }
1455
1478
  ws = null;
1456
1479
  reconnectTimer = null;
@@ -1475,7 +1498,8 @@ var HubClient = class {
1475
1498
  connectedAt: Date.now(),
1476
1499
  lastActivity: Date.now(),
1477
1500
  cwd: process.cwd(),
1478
- channelEnabled: true
1501
+ channelEnabled: true,
1502
+ peerName: this.getPeerName()
1479
1503
  }
1480
1504
  };
1481
1505
  this.ws.send(JSON.stringify(registration));