@highway1/cli 0.1.19 → 0.1.20

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
@@ -118221,23 +118221,16 @@ function registerInitCommand(program2) {
118221
118221
  init_esm_shims();
118222
118222
  init_dist3();
118223
118223
  function registerJoinCommand(program2) {
118224
- program2.command("join").description("Join the Clawiverse network").option("--bootstrap <peers...>", "Bootstrap peer addresses").option("--json", "Output messages as JSON (for agent automation)").action(async (options) => {
118224
+ program2.command("join").description("Join the Clawiverse network").option("--bootstrap <peers...>", "Bootstrap peer addresses").action(async (options) => {
118225
118225
  try {
118226
- const jsonMode = options.json;
118227
- if (!jsonMode) {
118228
- printHeader("Join Clawiverse Network");
118229
- }
118226
+ printHeader("Join Clawiverse Network");
118230
118227
  const identity3 = getIdentity();
118231
118228
  const card = getAgentCard();
118232
118229
  if (!identity3 || !card) {
118233
- if (jsonMode) {
118234
- console.log(JSON.stringify({ error: 'No identity found. Run "hw1 init" first.' }));
118235
- } else {
118236
- error('No identity found. Run "hw1 init" first.');
118237
- }
118230
+ error('No identity found. Run "hw1 init" first.');
118238
118231
  process.exit(1);
118239
118232
  }
118240
- const spin = jsonMode ? null : spinner("Starting libp2p node...");
118233
+ const spin = spinner("Starting libp2p node...");
118241
118234
  const keyPair = importKeyPair({
118242
118235
  publicKey: identity3.publicKey,
118243
118236
  privateKey: identity3.privateKey
@@ -118249,20 +118242,11 @@ function registerJoinCommand(program2) {
118249
118242
  enableDHT: true
118250
118243
  });
118251
118244
  await node.start();
118252
- if (spin) {
118253
- spin.succeed("Node started successfully!");
118254
- info(`Peer ID: ${node.getPeerId()}`);
118255
- info(`DID: ${identity3.did}`);
118256
- info(`Listening on: ${node.getMultiaddrs().join(", ")}`);
118257
- } else {
118258
- console.log(JSON.stringify({
118259
- event: "node_started",
118260
- peerId: node.getPeerId(),
118261
- did: identity3.did,
118262
- multiaddrs: node.getMultiaddrs()
118263
- }));
118264
- }
118265
- const connectSpin = jsonMode ? null : spinner("Connecting to bootstrap peers...");
118245
+ spin.succeed("Node started successfully!");
118246
+ info(`Peer ID: ${node.getPeerId()}`);
118247
+ info(`DID: ${identity3.did}`);
118248
+ info(`Listening on: ${node.getMultiaddrs().join(", ")}`);
118249
+ const connectSpin = spinner("Connecting to bootstrap peers...");
118266
118250
  await new Promise((resolve) => {
118267
118251
  const timeout = setTimeout(resolve, 1e4);
118268
118252
  node.libp2p.addEventListener("peer:connect", () => {
@@ -118270,10 +118254,8 @@ function registerJoinCommand(program2) {
118270
118254
  setTimeout(resolve, 500);
118271
118255
  }, { once: true });
118272
118256
  });
118273
- if (connectSpin) {
118274
- connectSpin.succeed("Connected to network!");
118275
- }
118276
- const cardSpin = jsonMode ? null : spinner("Publishing Agent Card to DHT...");
118257
+ connectSpin.succeed("Connected to network!");
118258
+ const cardSpin = spinner("Publishing Agent Card to DHT...");
118277
118259
  const directAddrs = node.getMultiaddrs();
118278
118260
  const relayAddrs = bootstrapPeers.map((relayAddr) => {
118279
118261
  const peerId = node.getPeerId();
@@ -118294,11 +118276,7 @@ function registerJoinCommand(program2) {
118294
118276
  );
118295
118277
  const dht = createDHTOperations(node.libp2p);
118296
118278
  await dht.publishAgentCard(signedCard);
118297
- if (cardSpin) {
118298
- cardSpin.succeed("Agent Card published!");
118299
- } else {
118300
- console.log(JSON.stringify({ event: "agent_card_published" }));
118301
- }
118279
+ cardSpin.succeed("Agent Card published!");
118302
118280
  const router = createMessageRouter(
118303
118281
  node.libp2p,
118304
118282
  async () => true,
@@ -118306,30 +118284,15 @@ function registerJoinCommand(program2) {
118306
118284
  );
118307
118285
  const messageHandler = async (envelope) => {
118308
118286
  const payload = envelope.payload;
118309
- if (jsonMode) {
118310
- console.log(JSON.stringify({
118311
- event: "message_received",
118312
- id: envelope.id,
118313
- from: envelope.from,
118314
- to: envelope.to,
118315
- protocol: envelope.protocol,
118316
- type: envelope.type,
118317
- payload,
118318
- timestamp: Date.now()
118319
- }));
118320
- } else {
118321
- console.log();
118322
- success(`>>> Received message from ${envelope.from}`);
118323
- info(` Message ID: ${envelope.id}`);
118324
- info(` Protocol: ${envelope.protocol}`);
118325
- info(` Type: ${envelope.type}`);
118326
- info(` Payload: ${JSON.stringify(payload, null, 2)}`);
118327
- console.log();
118328
- }
118287
+ console.log();
118288
+ success(`>>> Received message from ${envelope.from}`);
118289
+ info(` Message ID: ${envelope.id}`);
118290
+ info(` Protocol: ${envelope.protocol}`);
118291
+ info(` Type: ${envelope.type}`);
118292
+ info(` Payload: ${JSON.stringify(payload, null, 2)}`);
118293
+ console.log();
118329
118294
  if (envelope.type === "request") {
118330
- if (!jsonMode) {
118331
- info(" Sending acknowledgment response...");
118332
- }
118295
+ info(" Sending acknowledgment response...");
118333
118296
  const { createEnvelope: createEnvelope2, signEnvelope: signEnvelope2, sign: sign2 } = await Promise.resolve().then(() => (init_dist3(), dist_exports));
118334
118297
  const identity4 = getIdentity();
118335
118298
  const keyPair2 = importKeyPair({
@@ -118364,38 +118327,22 @@ function registerJoinCommand(program2) {
118364
118327
  router.registerHandler("/clawiverse/greet/1.0.0", messageHandler);
118365
118328
  router.registerCatchAllHandler(messageHandler);
118366
118329
  await router.start();
118367
- if (!jsonMode) {
118330
+ console.log();
118331
+ success("Successfully joined the Clawiverse network!");
118332
+ info("Listening for incoming messages...");
118333
+ info("Press Ctrl+C to stop");
118334
+ process.on("SIGINT", async () => {
118368
118335
  console.log();
118369
- success("Successfully joined the Clawiverse network!");
118370
- info("Listening for incoming messages...");
118371
- info("Press Ctrl+C to stop");
118372
- } else {
118373
- console.log(JSON.stringify({ event: "ready", status: "listening" }));
118374
- }
118375
- const shutdown = async () => {
118376
- if (!jsonMode) {
118377
- console.log();
118378
- const stopSpin = spinner("Stopping node...");
118379
- await router.stop();
118380
- await node.stop();
118381
- stopSpin.succeed("Node stopped");
118382
- } else {
118383
- await router.stop();
118384
- await node.stop();
118385
- console.log(JSON.stringify({ event: "shutdown", status: "stopped" }));
118386
- }
118336
+ const stopSpin = spinner("Stopping node...");
118337
+ await router.stop();
118338
+ await node.stop();
118339
+ stopSpin.succeed("Node stopped");
118387
118340
  process.exit(0);
118388
- };
118389
- process.on("SIGINT", shutdown);
118390
- process.on("SIGTERM", shutdown);
118341
+ });
118391
118342
  await new Promise(() => {
118392
118343
  });
118393
118344
  } catch (err2) {
118394
- if (options.json) {
118395
- console.log(JSON.stringify({ error: err2.message }));
118396
- } else {
118397
- error(`Failed to join network: ${err2.message}`);
118398
- }
118345
+ error(`Failed to join network: ${err2.message}`);
118399
118346
  process.exit(1);
118400
118347
  }
118401
118348
  });