iubcli 5.0.0 → 5.0.4

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/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/Ifaz2611/iubcli/main/icon/icon.svg" alt="IUB CLI icon" width="88" height="88" />
3
+ </p>
4
+
1
5
  # IUB CLI
2
6
 
3
7
  > Autonomous BYOK terminal coding agent for English workflows, with BUILD and PLAN modes, local-first configuration, and resilient free-model failover.
@@ -6,6 +10,7 @@
6
10
  [![Node.js Version](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen.svg?style=flat-square)](https://nodejs.org/)
7
11
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](license)
8
12
  [![BYOK](https://img.shields.io/badge/BYOK-100%25%20Serverless-blue.svg?style=flat-square)](#bring-your-own-key-byok)
13
+ [![GitHub](https://img.shields.io/badge/GitHub-Ifaz2611%2Fiubcli-181717.svg?style=flat-square&logo=github&logoColor=white)](https://github.com/Ifaz2611/iubcli)
9
14
 
10
15
  ```
11
16
  ██╗ ██╗ ██╗ ██████╗ ██████╗ ██╗ ██╗
@@ -319,10 +324,13 @@ iubcli/
319
324
  │ ├── detector.ts # project stack detection
320
325
  │ ├── image.ts # clipboard/file image payload loading
321
326
  │ └── mesh.ts # cross-instance peer networking
327
+ ├── icon/
328
+ │ └── icon.svg # project logo and favicon source
322
329
  ├── scripts/
323
330
  │ ├── test-tools.ts
324
331
  │ ├── test-image.ts
325
332
  │ ├── test-box.ts
333
+ │ ├── test-mesh.ts
326
334
  │ └── test-gemini-tools.ts
327
335
  ├── package.json
328
336
  ├── tsconfig.json
package/dist/index.js CHANGED
@@ -1419,7 +1419,6 @@ async function webSearch(query) {
1419
1419
  "Accept": "application/json"
1420
1420
  }
1421
1421
  });
1422
- clearTimeout(timeout);
1423
1422
  if (res.ok) {
1424
1423
  const data = await res.json();
1425
1424
  const results = [];
@@ -7828,6 +7827,25 @@ import crypto from "crypto";
7828
7827
  import { EventEmitter } from "events";
7829
7828
  import { WebSocketServer, WebSocket } from "ws";
7830
7829
  var DEFAULT_MESH_PORT = 49152;
7830
+ function mergePeerUpdate(current, incoming) {
7831
+ if (!incoming || typeof incoming !== "object") return null;
7832
+ const update = incoming;
7833
+ if (typeof update.nodeId !== "string" || update.nodeId !== current.nodeId) {
7834
+ return null;
7835
+ }
7836
+ if (update.role !== void 0 && update.role !== current.role) {
7837
+ return null;
7838
+ }
7839
+ const mode = update.mode === "build" || update.mode === "plan" ? update.mode : current.mode;
7840
+ const model = typeof update.model === "string" && update.model.trim().length > 0 ? update.model : current.model;
7841
+ const provider = typeof update.provider === "string" && update.provider.trim().length > 0 ? update.provider : current.provider;
7842
+ return {
7843
+ ...current,
7844
+ mode,
7845
+ model,
7846
+ provider
7847
+ };
7848
+ }
7831
7849
  function getOrCreateMeshToken(customToken) {
7832
7850
  if (customToken && customToken.trim().length > 0) {
7833
7851
  return customToken.trim();
@@ -7993,27 +8011,54 @@ var MeshNode = class extends EventEmitter {
7993
8011
  ws.close(4001, "Unauthorized");
7994
8012
  return;
7995
8013
  }
8014
+ if (!msg.peer || typeof msg.peer !== "object" || typeof msg.peer.nodeId !== "string" || msg.peer.nodeId.trim().length === 0) {
8015
+ ws.send(JSON.stringify({ type: "AUTH_FAIL", reason: "Invalid peer identity" }));
8016
+ ws.close(4001, "Invalid Identity");
8017
+ return;
8018
+ }
7996
8019
  clearTimeout(authTimeout);
7997
- authedPeer = msg.peer;
7998
- this.connectedClients.set(ws, authedPeer);
7999
- this.peers.set(authedPeer.nodeId, authedPeer);
8020
+ const previousPeer = authedPeer;
8021
+ if (previousPeer && msg.peer.nodeId !== previousPeer.nodeId) {
8022
+ ws.send(
8023
+ JSON.stringify({
8024
+ type: "AUTH_FAIL",
8025
+ reason: "Node identity cannot change after authentication"
8026
+ })
8027
+ );
8028
+ ws.close(4003, "Identity Change Rejected");
8029
+ return;
8030
+ }
8031
+ const authed = previousPeer ? {
8032
+ ...previousPeer,
8033
+ role: typeof msg.peer.role === "string" && msg.peer.role.trim().length > 0 ? msg.peer.role : previousPeer.role,
8034
+ mode: msg.peer.mode === "build" || msg.peer.mode === "plan" ? msg.peer.mode : previousPeer.mode,
8035
+ model: typeof msg.peer.model === "string" && msg.peer.model.trim().length > 0 ? msg.peer.model : previousPeer.model,
8036
+ provider: typeof msg.peer.provider === "string" && msg.peer.provider.trim().length > 0 ? msg.peer.provider : previousPeer.provider
8037
+ } : msg.peer;
8038
+ authedPeer = authed;
8039
+ this.connectedClients.set(ws, authed);
8040
+ this.peers.set(authed.nodeId, authed);
8000
8041
  const peerList = this.listPeers();
8001
8042
  ws.send(
8002
8043
  JSON.stringify({
8003
8044
  type: "AUTH_OK",
8004
- assignedNodeId: authedPeer.nodeId,
8045
+ assignedNodeId: authed.nodeId,
8005
8046
  peers: peerList
8006
8047
  })
8007
8048
  );
8008
8049
  this.broadcast(
8009
8050
  {
8010
8051
  type: "PEER_JOINED",
8011
- peer: authedPeer
8052
+ peer: authed
8012
8053
  },
8013
8054
  ws
8014
8055
  );
8015
- this.emit("peer_connected", authedPeer);
8016
- this.onPeerConnectCallback?.(authedPeer);
8056
+ if (previousPeer) {
8057
+ this.emit("peer_updated", authed);
8058
+ } else {
8059
+ this.emit("peer_connected", authed);
8060
+ this.onPeerConnectCallback?.(authed);
8061
+ }
8017
8062
  return;
8018
8063
  }
8019
8064
  if (!authedPeer) {
@@ -8029,11 +8074,15 @@ var MeshNode = class extends EventEmitter {
8029
8074
  return;
8030
8075
  }
8031
8076
  if (msg.type === "PEER_UPDATE") {
8032
- authedPeer = { ...authedPeer, ...msg.peer };
8033
- this.connectedClients.set(ws, authedPeer);
8034
- this.peers.set(authedPeer.nodeId, authedPeer);
8035
- this.broadcast(msg, ws);
8036
- this.emit("peer_updated", authedPeer);
8077
+ const updated = mergePeerUpdate(authedPeer, msg.peer);
8078
+ if (!updated) {
8079
+ return;
8080
+ }
8081
+ authedPeer = updated;
8082
+ this.connectedClients.set(ws, updated);
8083
+ this.peers.set(updated.nodeId, updated);
8084
+ this.broadcast({ type: "PEER_UPDATE", peer: updated }, ws);
8085
+ this.emit("peer_updated", updated);
8037
8086
  return;
8038
8087
  }
8039
8088
  } catch {
@@ -8044,7 +8093,9 @@ var MeshNode = class extends EventEmitter {
8044
8093
  if (authedPeer) {
8045
8094
  const departing = authedPeer;
8046
8095
  this.connectedClients.delete(ws);
8047
- this.peers.delete(departing.nodeId);
8096
+ if (this.peers.get(departing.nodeId) === departing) {
8097
+ this.peers.delete(departing.nodeId);
8098
+ }
8048
8099
  this.broadcast({ type: "PEER_LEFT", nodeId: departing.nodeId });
8049
8100
  this.emit("peer_disconnected", departing);
8050
8101
  this.onPeerDisconnectCallback?.(departing);
@@ -8107,9 +8158,14 @@ var MeshNode = class extends EventEmitter {
8107
8158
  }
8108
8159
  if (msg.type === "PEER_JOINED") {
8109
8160
  if (msg.peer.nodeId !== this.nodeId) {
8161
+ const existing = this.peers.get(msg.peer.nodeId);
8110
8162
  this.peers.set(msg.peer.nodeId, msg.peer);
8111
- this.emit("peer_connected", msg.peer);
8112
- this.onPeerConnectCallback?.(msg.peer);
8163
+ if (existing) {
8164
+ this.emit("peer_updated", msg.peer);
8165
+ } else {
8166
+ this.emit("peer_connected", msg.peer);
8167
+ this.onPeerConnectCallback?.(msg.peer);
8168
+ }
8113
8169
  }
8114
8170
  return;
8115
8171
  }
@@ -8123,10 +8179,12 @@ var MeshNode = class extends EventEmitter {
8123
8179
  return;
8124
8180
  }
8125
8181
  if (msg.type === "PEER_UPDATE") {
8126
- if (msg.peer.nodeId !== this.nodeId) {
8127
- this.peers.set(msg.peer.nodeId, msg.peer);
8128
- this.emit("peer_updated", msg.peer);
8129
- }
8182
+ const current = this.peers.get(msg.peer.nodeId);
8183
+ if (!current) return;
8184
+ const updated = mergePeerUpdate(current, msg.peer);
8185
+ if (!updated) return;
8186
+ this.peers.set(updated.nodeId, updated);
8187
+ this.emit("peer_updated", updated);
8130
8188
  return;
8131
8189
  }
8132
8190
  if (msg.type === "RPC_REQUEST") {
@@ -8462,10 +8520,24 @@ ${out}`;
8462
8520
  * Broadcast state update (e.g. mode change or model change).
8463
8521
  */
8464
8522
  updateState(updates) {
8523
+ const roleChanged = updates.role !== void 0 && updates.role !== this.role;
8465
8524
  if (updates.mode) this.mode = updates.mode;
8466
8525
  if (updates.model) this.model = updates.model;
8467
8526
  if (updates.role) this.role = updates.role;
8468
8527
  const myInfo = this.getMyPeerInfo();
8528
+ if (roleChanged) {
8529
+ if (this.isHost) {
8530
+ this.broadcast({ type: "PEER_JOINED", peer: myInfo });
8531
+ } else if (this.clientWs && this.clientWs.readyState === WebSocket.OPEN) {
8532
+ const authMsg = {
8533
+ type: "AUTH",
8534
+ token: this.token,
8535
+ peer: myInfo
8536
+ };
8537
+ this.clientWs.send(JSON.stringify(authMsg));
8538
+ }
8539
+ return;
8540
+ }
8469
8541
  const updateMsg = {
8470
8542
  type: "PEER_UPDATE",
8471
8543
  peer: myInfo