iubcli 4.2.19 → 5.0.3

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
@@ -333,6 +341,8 @@ iubcli/
333
341
 
334
342
  ## Development
335
343
 
344
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the full development guide.
345
+
336
346
  Clone the repository:
337
347
 
338
348
  ```bash
@@ -367,6 +377,16 @@ Package scripts:
367
377
 
368
378
  ---
369
379
 
380
+ ## Documentation
381
+
382
+ - **[GET-STARTED.md](GET-STARTED.md)** — step-by-step guide for first-time users
383
+ - **[CONTRIBUTING.md](CONTRIBUTING.md)** — how to set up the dev environment and submit PRs
384
+ - **[CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md)** — community standards
385
+ - **[SECURITY.md](SECURITY.md)** — how to report vulnerabilities and security notes
386
+ - **[RELEASING.md](RELEASING.md)** — npm release process (maintainers)
387
+
388
+ ---
389
+
370
390
  ## License
371
391
 
372
392
  [MIT](license)
package/dist/index.js CHANGED
@@ -1200,6 +1200,9 @@ function runActualProcess(command, signal, cwd = process.cwd()) {
1200
1200
  isTimedOut = true;
1201
1201
  terminateChildTree(child);
1202
1202
  }, timeoutMs);
1203
+ if (signal?.aborted) {
1204
+ onAbort();
1205
+ }
1203
1206
  child.stdout.on("data", (data) => {
1204
1207
  if (stdout.length < 20 * 1024 * 1024) {
1205
1208
  stdout += data.toString();
@@ -7825,6 +7828,25 @@ import crypto from "crypto";
7825
7828
  import { EventEmitter } from "events";
7826
7829
  import { WebSocketServer, WebSocket } from "ws";
7827
7830
  var DEFAULT_MESH_PORT = 49152;
7831
+ function mergePeerUpdate(current, incoming) {
7832
+ if (!incoming || typeof incoming !== "object") return null;
7833
+ const update = incoming;
7834
+ if (typeof update.nodeId !== "string" || update.nodeId !== current.nodeId) {
7835
+ return null;
7836
+ }
7837
+ if (update.role !== void 0 && update.role !== current.role) {
7838
+ return null;
7839
+ }
7840
+ const mode = update.mode === "build" || update.mode === "plan" ? update.mode : current.mode;
7841
+ const model = typeof update.model === "string" && update.model.trim().length > 0 ? update.model : current.model;
7842
+ const provider = typeof update.provider === "string" && update.provider.trim().length > 0 ? update.provider : current.provider;
7843
+ return {
7844
+ ...current,
7845
+ mode,
7846
+ model,
7847
+ provider
7848
+ };
7849
+ }
7828
7850
  function getOrCreateMeshToken(customToken) {
7829
7851
  if (customToken && customToken.trim().length > 0) {
7830
7852
  return customToken.trim();
@@ -7990,27 +8012,54 @@ var MeshNode = class extends EventEmitter {
7990
8012
  ws.close(4001, "Unauthorized");
7991
8013
  return;
7992
8014
  }
8015
+ if (!msg.peer || typeof msg.peer !== "object" || typeof msg.peer.nodeId !== "string" || msg.peer.nodeId.trim().length === 0) {
8016
+ ws.send(JSON.stringify({ type: "AUTH_FAIL", reason: "Invalid peer identity" }));
8017
+ ws.close(4001, "Invalid Identity");
8018
+ return;
8019
+ }
7993
8020
  clearTimeout(authTimeout);
7994
- authedPeer = msg.peer;
7995
- this.connectedClients.set(ws, authedPeer);
7996
- this.peers.set(authedPeer.nodeId, authedPeer);
8021
+ const previousPeer = authedPeer;
8022
+ if (previousPeer && msg.peer.nodeId !== previousPeer.nodeId) {
8023
+ ws.send(
8024
+ JSON.stringify({
8025
+ type: "AUTH_FAIL",
8026
+ reason: "Node identity cannot change after authentication"
8027
+ })
8028
+ );
8029
+ ws.close(4003, "Identity Change Rejected");
8030
+ return;
8031
+ }
8032
+ const authed = previousPeer ? {
8033
+ ...previousPeer,
8034
+ role: typeof msg.peer.role === "string" && msg.peer.role.trim().length > 0 ? msg.peer.role : previousPeer.role,
8035
+ mode: msg.peer.mode === "build" || msg.peer.mode === "plan" ? msg.peer.mode : previousPeer.mode,
8036
+ model: typeof msg.peer.model === "string" && msg.peer.model.trim().length > 0 ? msg.peer.model : previousPeer.model,
8037
+ provider: typeof msg.peer.provider === "string" && msg.peer.provider.trim().length > 0 ? msg.peer.provider : previousPeer.provider
8038
+ } : msg.peer;
8039
+ authedPeer = authed;
8040
+ this.connectedClients.set(ws, authed);
8041
+ this.peers.set(authed.nodeId, authed);
7997
8042
  const peerList = this.listPeers();
7998
8043
  ws.send(
7999
8044
  JSON.stringify({
8000
8045
  type: "AUTH_OK",
8001
- assignedNodeId: authedPeer.nodeId,
8046
+ assignedNodeId: authed.nodeId,
8002
8047
  peers: peerList
8003
8048
  })
8004
8049
  );
8005
8050
  this.broadcast(
8006
8051
  {
8007
8052
  type: "PEER_JOINED",
8008
- peer: authedPeer
8053
+ peer: authed
8009
8054
  },
8010
8055
  ws
8011
8056
  );
8012
- this.emit("peer_connected", authedPeer);
8013
- this.onPeerConnectCallback?.(authedPeer);
8057
+ if (previousPeer) {
8058
+ this.emit("peer_updated", authed);
8059
+ } else {
8060
+ this.emit("peer_connected", authed);
8061
+ this.onPeerConnectCallback?.(authed);
8062
+ }
8014
8063
  return;
8015
8064
  }
8016
8065
  if (!authedPeer) {
@@ -8026,11 +8075,15 @@ var MeshNode = class extends EventEmitter {
8026
8075
  return;
8027
8076
  }
8028
8077
  if (msg.type === "PEER_UPDATE") {
8029
- authedPeer = { ...authedPeer, ...msg.peer };
8030
- this.connectedClients.set(ws, authedPeer);
8031
- this.peers.set(authedPeer.nodeId, authedPeer);
8032
- this.broadcast(msg, ws);
8033
- this.emit("peer_updated", authedPeer);
8078
+ const updated = mergePeerUpdate(authedPeer, msg.peer);
8079
+ if (!updated) {
8080
+ return;
8081
+ }
8082
+ authedPeer = updated;
8083
+ this.connectedClients.set(ws, updated);
8084
+ this.peers.set(updated.nodeId, updated);
8085
+ this.broadcast({ type: "PEER_UPDATE", peer: updated }, ws);
8086
+ this.emit("peer_updated", updated);
8034
8087
  return;
8035
8088
  }
8036
8089
  } catch {
@@ -8041,7 +8094,9 @@ var MeshNode = class extends EventEmitter {
8041
8094
  if (authedPeer) {
8042
8095
  const departing = authedPeer;
8043
8096
  this.connectedClients.delete(ws);
8044
- this.peers.delete(departing.nodeId);
8097
+ if (this.peers.get(departing.nodeId) === departing) {
8098
+ this.peers.delete(departing.nodeId);
8099
+ }
8045
8100
  this.broadcast({ type: "PEER_LEFT", nodeId: departing.nodeId });
8046
8101
  this.emit("peer_disconnected", departing);
8047
8102
  this.onPeerDisconnectCallback?.(departing);
@@ -8104,9 +8159,14 @@ var MeshNode = class extends EventEmitter {
8104
8159
  }
8105
8160
  if (msg.type === "PEER_JOINED") {
8106
8161
  if (msg.peer.nodeId !== this.nodeId) {
8162
+ const existing = this.peers.get(msg.peer.nodeId);
8107
8163
  this.peers.set(msg.peer.nodeId, msg.peer);
8108
- this.emit("peer_connected", msg.peer);
8109
- this.onPeerConnectCallback?.(msg.peer);
8164
+ if (existing) {
8165
+ this.emit("peer_updated", msg.peer);
8166
+ } else {
8167
+ this.emit("peer_connected", msg.peer);
8168
+ this.onPeerConnectCallback?.(msg.peer);
8169
+ }
8110
8170
  }
8111
8171
  return;
8112
8172
  }
@@ -8120,10 +8180,12 @@ var MeshNode = class extends EventEmitter {
8120
8180
  return;
8121
8181
  }
8122
8182
  if (msg.type === "PEER_UPDATE") {
8123
- if (msg.peer.nodeId !== this.nodeId) {
8124
- this.peers.set(msg.peer.nodeId, msg.peer);
8125
- this.emit("peer_updated", msg.peer);
8126
- }
8183
+ const current = this.peers.get(msg.peer.nodeId);
8184
+ if (!current) return;
8185
+ const updated = mergePeerUpdate(current, msg.peer);
8186
+ if (!updated) return;
8187
+ this.peers.set(updated.nodeId, updated);
8188
+ this.emit("peer_updated", updated);
8127
8189
  return;
8128
8190
  }
8129
8191
  if (msg.type === "RPC_REQUEST") {
@@ -8459,10 +8521,24 @@ ${out}`;
8459
8521
  * Broadcast state update (e.g. mode change or model change).
8460
8522
  */
8461
8523
  updateState(updates) {
8524
+ const roleChanged = updates.role !== void 0 && updates.role !== this.role;
8462
8525
  if (updates.mode) this.mode = updates.mode;
8463
8526
  if (updates.model) this.model = updates.model;
8464
8527
  if (updates.role) this.role = updates.role;
8465
8528
  const myInfo = this.getMyPeerInfo();
8529
+ if (roleChanged) {
8530
+ if (this.isHost) {
8531
+ this.broadcast({ type: "PEER_JOINED", peer: myInfo });
8532
+ } else if (this.clientWs && this.clientWs.readyState === WebSocket.OPEN) {
8533
+ const authMsg = {
8534
+ type: "AUTH",
8535
+ token: this.token,
8536
+ peer: myInfo
8537
+ };
8538
+ this.clientWs.send(JSON.stringify(authMsg));
8539
+ }
8540
+ return;
8541
+ }
8466
8542
  const updateMsg = {
8467
8543
  type: "PEER_UPDATE",
8468
8544
  peer: myInfo