@highway1/cli 0.1.18 → 0.1.19
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 +90 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/join.ts +89 -32
package/dist/index.js
CHANGED
|
@@ -116189,7 +116189,12 @@ async function createNode(config2) {
|
|
|
116189
116189
|
}
|
|
116190
116190
|
};
|
|
116191
116191
|
if (enableRelay) {
|
|
116192
|
-
libp2pConfig.services.relay = circuitRelayServer(
|
|
116192
|
+
libp2pConfig.services.relay = circuitRelayServer({
|
|
116193
|
+
reservations: {
|
|
116194
|
+
maxReservations: 100
|
|
116195
|
+
// Allow up to 100 concurrent relay reservations
|
|
116196
|
+
}
|
|
116197
|
+
});
|
|
116193
116198
|
}
|
|
116194
116199
|
if (enableDHT) {
|
|
116195
116200
|
libp2pConfig.services.dht = kadDHT({
|
|
@@ -118216,16 +118221,23 @@ function registerInitCommand(program2) {
|
|
|
118216
118221
|
init_esm_shims();
|
|
118217
118222
|
init_dist3();
|
|
118218
118223
|
function registerJoinCommand(program2) {
|
|
118219
|
-
program2.command("join").description("Join the Clawiverse network").option("--bootstrap <peers...>", "Bootstrap peer addresses").action(async (options) => {
|
|
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) => {
|
|
118220
118225
|
try {
|
|
118221
|
-
|
|
118226
|
+
const jsonMode = options.json;
|
|
118227
|
+
if (!jsonMode) {
|
|
118228
|
+
printHeader("Join Clawiverse Network");
|
|
118229
|
+
}
|
|
118222
118230
|
const identity3 = getIdentity();
|
|
118223
118231
|
const card = getAgentCard();
|
|
118224
118232
|
if (!identity3 || !card) {
|
|
118225
|
-
|
|
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
|
+
}
|
|
118226
118238
|
process.exit(1);
|
|
118227
118239
|
}
|
|
118228
|
-
const spin = spinner("Starting libp2p node...");
|
|
118240
|
+
const spin = jsonMode ? null : spinner("Starting libp2p node...");
|
|
118229
118241
|
const keyPair = importKeyPair({
|
|
118230
118242
|
publicKey: identity3.publicKey,
|
|
118231
118243
|
privateKey: identity3.privateKey
|
|
@@ -118237,11 +118249,20 @@ function registerJoinCommand(program2) {
|
|
|
118237
118249
|
enableDHT: true
|
|
118238
118250
|
});
|
|
118239
118251
|
await node.start();
|
|
118240
|
-
spin
|
|
118241
|
-
|
|
118242
|
-
|
|
118243
|
-
|
|
118244
|
-
|
|
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
118266
|
await new Promise((resolve) => {
|
|
118246
118267
|
const timeout = setTimeout(resolve, 1e4);
|
|
118247
118268
|
node.libp2p.addEventListener("peer:connect", () => {
|
|
@@ -118249,8 +118270,10 @@ function registerJoinCommand(program2) {
|
|
|
118249
118270
|
setTimeout(resolve, 500);
|
|
118250
118271
|
}, { once: true });
|
|
118251
118272
|
});
|
|
118252
|
-
connectSpin
|
|
118253
|
-
|
|
118273
|
+
if (connectSpin) {
|
|
118274
|
+
connectSpin.succeed("Connected to network!");
|
|
118275
|
+
}
|
|
118276
|
+
const cardSpin = jsonMode ? null : spinner("Publishing Agent Card to DHT...");
|
|
118254
118277
|
const directAddrs = node.getMultiaddrs();
|
|
118255
118278
|
const relayAddrs = bootstrapPeers.map((relayAddr) => {
|
|
118256
118279
|
const peerId = node.getPeerId();
|
|
@@ -118271,7 +118294,11 @@ function registerJoinCommand(program2) {
|
|
|
118271
118294
|
);
|
|
118272
118295
|
const dht = createDHTOperations(node.libp2p);
|
|
118273
118296
|
await dht.publishAgentCard(signedCard);
|
|
118274
|
-
cardSpin
|
|
118297
|
+
if (cardSpin) {
|
|
118298
|
+
cardSpin.succeed("Agent Card published!");
|
|
118299
|
+
} else {
|
|
118300
|
+
console.log(JSON.stringify({ event: "agent_card_published" }));
|
|
118301
|
+
}
|
|
118275
118302
|
const router = createMessageRouter(
|
|
118276
118303
|
node.libp2p,
|
|
118277
118304
|
async () => true,
|
|
@@ -118279,15 +118306,30 @@ function registerJoinCommand(program2) {
|
|
|
118279
118306
|
);
|
|
118280
118307
|
const messageHandler = async (envelope) => {
|
|
118281
118308
|
const payload = envelope.payload;
|
|
118282
|
-
|
|
118283
|
-
|
|
118284
|
-
|
|
118285
|
-
|
|
118286
|
-
|
|
118287
|
-
|
|
118288
|
-
|
|
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
|
+
}
|
|
118289
118329
|
if (envelope.type === "request") {
|
|
118290
|
-
|
|
118330
|
+
if (!jsonMode) {
|
|
118331
|
+
info(" Sending acknowledgment response...");
|
|
118332
|
+
}
|
|
118291
118333
|
const { createEnvelope: createEnvelope2, signEnvelope: signEnvelope2, sign: sign2 } = await Promise.resolve().then(() => (init_dist3(), dist_exports));
|
|
118292
118334
|
const identity4 = getIdentity();
|
|
118293
118335
|
const keyPair2 = importKeyPair({
|
|
@@ -118322,22 +118364,38 @@ function registerJoinCommand(program2) {
|
|
|
118322
118364
|
router.registerHandler("/clawiverse/greet/1.0.0", messageHandler);
|
|
118323
118365
|
router.registerCatchAllHandler(messageHandler);
|
|
118324
118366
|
await router.start();
|
|
118325
|
-
|
|
118326
|
-
success("Successfully joined the Clawiverse network!");
|
|
118327
|
-
info("Listening for incoming messages...");
|
|
118328
|
-
info("Press Ctrl+C to stop");
|
|
118329
|
-
process.on("SIGINT", async () => {
|
|
118367
|
+
if (!jsonMode) {
|
|
118330
118368
|
console.log();
|
|
118331
|
-
|
|
118332
|
-
|
|
118333
|
-
|
|
118334
|
-
|
|
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
|
+
}
|
|
118335
118387
|
process.exit(0);
|
|
118336
|
-
}
|
|
118388
|
+
};
|
|
118389
|
+
process.on("SIGINT", shutdown);
|
|
118390
|
+
process.on("SIGTERM", shutdown);
|
|
118337
118391
|
await new Promise(() => {
|
|
118338
118392
|
});
|
|
118339
118393
|
} catch (err2) {
|
|
118340
|
-
|
|
118394
|
+
if (options.json) {
|
|
118395
|
+
console.log(JSON.stringify({ error: err2.message }));
|
|
118396
|
+
} else {
|
|
118397
|
+
error(`Failed to join network: ${err2.message}`);
|
|
118398
|
+
}
|
|
118341
118399
|
process.exit(1);
|
|
118342
118400
|
}
|
|
118343
118401
|
});
|