@highway1/cli 0.1.47 → 0.1.49

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Clawiverse Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js CHANGED
@@ -116805,14 +116805,25 @@ function createMessageRouter(libp2p, verifyFn, dht, relayPeers) {
116805
116805
  });
116806
116806
  const s2 = await conn.newStream(PROTOCOL_PREFIX3, { runOnLimitedConnection: true });
116807
116807
  logger5.info("Direct dial succeeded", { addr });
116808
- return s2;
116808
+ return { conn, stream: s2 };
116809
116809
  } catch {
116810
116810
  return null;
116811
116811
  }
116812
116812
  });
116813
- stream = await Promise.race(
116814
- directDialPromises.map((p2) => p2.then((s2) => s2 || Promise.reject()))
116813
+ const winner = await Promise.race(
116814
+ directDialPromises.map((p2) => p2.then((r2) => r2 || Promise.reject()))
116815
116815
  ).catch(() => void 0);
116816
+ if (winner) {
116817
+ stream = winner.stream;
116818
+ Promise.allSettled(directDialPromises).then((results) => {
116819
+ for (const result of results) {
116820
+ if (result.status === "fulfilled" && result.value && result.value.stream !== stream) {
116821
+ result.value.conn.close().catch(() => {
116822
+ });
116823
+ }
116824
+ }
116825
+ });
116826
+ }
116816
116827
  }
116817
116828
  let lastError;
116818
116829
  if (!stream) {
@@ -116830,16 +116841,27 @@ function createMessageRouter(libp2p, verifyFn, dht, relayPeers) {
116830
116841
  logger5.info("Relay connection established", { addr });
116831
116842
  const s2 = await conn.newStream(PROTOCOL_PREFIX3, { runOnLimitedConnection: true });
116832
116843
  logger5.info("Relay stream opened", { addr });
116833
- return s2;
116844
+ return { conn, stream: s2 };
116834
116845
  } catch (relayErr) {
116835
116846
  logger5.warn("Relay dial failed", { addr, error: relayErr.message });
116836
116847
  lastError = relayErr;
116837
116848
  return null;
116838
116849
  }
116839
116850
  });
116840
- stream = await Promise.race(
116841
- relayDialPromises.map((p2) => p2.then((s2) => s2 || Promise.reject()))
116851
+ const winner = await Promise.race(
116852
+ relayDialPromises.map((p2) => p2.then((r2) => r2 || Promise.reject()))
116842
116853
  ).catch(() => void 0);
116854
+ if (winner) {
116855
+ stream = winner.stream;
116856
+ Promise.allSettled(relayDialPromises).then((results) => {
116857
+ for (const result of results) {
116858
+ if (result.status === "fulfilled" && result.value && result.value.stream !== stream) {
116859
+ result.value.conn.close().catch(() => {
116860
+ });
116861
+ }
116862
+ }
116863
+ });
116864
+ }
116843
116865
  }
116844
116866
  }
116845
116867
  if (!stream && dht && "queryRelayPeers" in dht) {
@@ -116941,6 +116963,10 @@ async function handleIncomingStream(stream, handlers, catchAllHandler, verifyFn)
116941
116963
  chunks.push(chunk.subarray());
116942
116964
  }
116943
116965
  const data = concatUint8Arrays(chunks);
116966
+ if (data.length === 0) {
116967
+ logger5.debug("Received empty stream, ignoring");
116968
+ return;
116969
+ }
116944
116970
  const envelope = decodeMessage2(data);
116945
116971
  if (!validateEnvelope(envelope)) {
116946
116972
  logger5.warn("Received invalid message envelope");
@@ -118899,6 +118925,7 @@ function registerSendCommand(program2) {
118899
118925
  return;
118900
118926
  } catch (err2) {
118901
118927
  spin2.fail("Daemon send failed, falling back to ephemeral node");
118928
+ info(`Daemon error: ${err2.message}`);
118902
118929
  console.log();
118903
118930
  info('Tip: Restart daemon with "clawiverse daemon restart" if issues persist');
118904
118931
  console.log();
@@ -118918,7 +118945,8 @@ function registerSendCommand(program2) {
118918
118945
  const node = await createNode({
118919
118946
  keyPair,
118920
118947
  bootstrapPeers,
118921
- enableDHT: true
118948
+ enableDHT: true,
118949
+ reserveRelaySlot: bootstrapPeers.length > 0
118922
118950
  });
118923
118951
  const identifyDone = new Promise((resolve2) => {
118924
118952
  const timeout = setTimeout(resolve2, 2e3);
@@ -118964,9 +118992,9 @@ function registerSendCommand(program2) {
118964
118992
  let peerHint = void 0;
118965
118993
  if (options.peer) {
118966
118994
  const parts = options.peer.split("/p2p/");
118967
- if (parts.length === 2) {
118995
+ if (parts.length >= 2) {
118968
118996
  peerHint = {
118969
- peerId: parts[1],
118997
+ peerId: parts[parts.length - 1],
118970
118998
  multiaddrs: [options.peer]
118971
118999
  };
118972
119000
  info(`Direct peer: ${options.peer}`);
@@ -119367,7 +119395,8 @@ var ClawDaemon = class {
119367
119395
  this.node = await createNode({
119368
119396
  keyPair,
119369
119397
  bootstrapPeers: this.bootstrapPeers,
119370
- enableDHT: true
119398
+ enableDHT: true,
119399
+ reserveRelaySlot: this.bootstrapPeers.length > 0
119371
119400
  });
119372
119401
  await this.node.start();
119373
119402
  logger12.info("Node started", { peerId: this.node.getPeerId() });
@@ -119467,9 +119496,9 @@ var ClawDaemon = class {
119467
119496
  let peerHint = void 0;
119468
119497
  if (peer) {
119469
119498
  const parts = peer.split("/p2p/");
119470
- if (parts.length === 2) {
119499
+ if (parts.length >= 2) {
119471
119500
  peerHint = {
119472
- peerId: parts[1],
119501
+ peerId: parts[parts.length - 1],
119473
119502
  multiaddrs: [peer]
119474
119503
  };
119475
119504
  }