@highway1/cli 0.1.19 → 0.1.21
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 +74 -138
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/card.ts +46 -29
- package/src/commands/init.ts +6 -31
- package/src/commands/join.ts +32 -89
package/dist/index.js
CHANGED
|
@@ -19,8 +19,8 @@ import { Command } from 'commander';
|
|
|
19
19
|
import Conf from 'conf';
|
|
20
20
|
import chalk from 'chalk';
|
|
21
21
|
import ora from 'ora';
|
|
22
|
-
import inquirer from 'inquirer';
|
|
23
22
|
import Table from 'cli-table3';
|
|
23
|
+
import inquirer from 'inquirer';
|
|
24
24
|
|
|
25
25
|
var __create = Object.create;
|
|
26
26
|
var __defProp = Object.defineProperty;
|
|
@@ -118159,36 +118159,16 @@ function printSection(title) {
|
|
|
118159
118159
|
console.log();
|
|
118160
118160
|
console.log(chalk.bold(title));
|
|
118161
118161
|
}
|
|
118162
|
+
|
|
118163
|
+
// src/commands/init.ts
|
|
118162
118164
|
function registerInitCommand(program2) {
|
|
118163
|
-
program2.command("init").description("Initialize a new Clawiverse identity").option("--name <name>", "Agent name").option("--description <description>", "Agent description").option("--force", "Overwrite existing identity").action(async (options) => {
|
|
118165
|
+
program2.command("init").description("Initialize a new Clawiverse identity").option("--name <name>", "Agent name", "My Agent").option("--description <description>", "Agent description", "A Clawiverse agent").option("--force", "Overwrite existing identity").action(async (options) => {
|
|
118164
118166
|
try {
|
|
118165
118167
|
printHeader("Initialize Clawiverse Identity");
|
|
118166
118168
|
if (hasIdentity() && !options.force) {
|
|
118167
118169
|
error("Identity already exists. Use --force to overwrite.");
|
|
118168
118170
|
process.exit(1);
|
|
118169
118171
|
}
|
|
118170
|
-
let name3 = options.name;
|
|
118171
|
-
let description = options.description;
|
|
118172
|
-
if (!name3) name3 = "My Agent";
|
|
118173
|
-
if (!description) description = "A Clawiverse agent";
|
|
118174
|
-
if (!options.name) {
|
|
118175
|
-
const { name: inputName } = await inquirer.prompt({
|
|
118176
|
-
type: "input",
|
|
118177
|
-
name: "name",
|
|
118178
|
-
message: "Agent name:",
|
|
118179
|
-
default: name3
|
|
118180
|
-
});
|
|
118181
|
-
name3 = inputName || name3;
|
|
118182
|
-
}
|
|
118183
|
-
if (!options.description) {
|
|
118184
|
-
const { description: inputDesc } = await inquirer.prompt({
|
|
118185
|
-
type: "input",
|
|
118186
|
-
name: "description",
|
|
118187
|
-
message: "Agent description:",
|
|
118188
|
-
default: description
|
|
118189
|
-
});
|
|
118190
|
-
description = inputDesc || description;
|
|
118191
|
-
}
|
|
118192
118172
|
const spin = spinner("Generating key pair...");
|
|
118193
118173
|
const keyPair = await generateKeyPair2();
|
|
118194
118174
|
const exported = exportKeyPair(keyPair);
|
|
@@ -118199,15 +118179,15 @@ function registerInitCommand(program2) {
|
|
|
118199
118179
|
privateKey: exported.privateKey
|
|
118200
118180
|
});
|
|
118201
118181
|
setAgentCard({
|
|
118202
|
-
name:
|
|
118203
|
-
description,
|
|
118182
|
+
name: options.name,
|
|
118183
|
+
description: options.description,
|
|
118204
118184
|
capabilities: []
|
|
118205
118185
|
});
|
|
118206
118186
|
spin.succeed("Identity created successfully!");
|
|
118207
118187
|
console.log();
|
|
118208
118188
|
printKeyValue("DID", did);
|
|
118209
|
-
printKeyValue("Name",
|
|
118210
|
-
printKeyValue("Description", description);
|
|
118189
|
+
printKeyValue("Name", options.name);
|
|
118190
|
+
printKeyValue("Description", options.description);
|
|
118211
118191
|
console.log();
|
|
118212
118192
|
success('Run "hw1 join" to connect to the network');
|
|
118213
118193
|
} catch (err2) {
|
|
@@ -118221,23 +118201,16 @@ function registerInitCommand(program2) {
|
|
|
118221
118201
|
init_esm_shims();
|
|
118222
118202
|
init_dist3();
|
|
118223
118203
|
function registerJoinCommand(program2) {
|
|
118224
|
-
program2.command("join").description("Join the Clawiverse network").option("--bootstrap <peers...>", "Bootstrap peer addresses").
|
|
118204
|
+
program2.command("join").description("Join the Clawiverse network").option("--bootstrap <peers...>", "Bootstrap peer addresses").action(async (options) => {
|
|
118225
118205
|
try {
|
|
118226
|
-
|
|
118227
|
-
if (!jsonMode) {
|
|
118228
|
-
printHeader("Join Clawiverse Network");
|
|
118229
|
-
}
|
|
118206
|
+
printHeader("Join Clawiverse Network");
|
|
118230
118207
|
const identity3 = getIdentity();
|
|
118231
118208
|
const card = getAgentCard();
|
|
118232
118209
|
if (!identity3 || !card) {
|
|
118233
|
-
|
|
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
|
-
}
|
|
118210
|
+
error('No identity found. Run "hw1 init" first.');
|
|
118238
118211
|
process.exit(1);
|
|
118239
118212
|
}
|
|
118240
|
-
const spin =
|
|
118213
|
+
const spin = spinner("Starting libp2p node...");
|
|
118241
118214
|
const keyPair = importKeyPair({
|
|
118242
118215
|
publicKey: identity3.publicKey,
|
|
118243
118216
|
privateKey: identity3.privateKey
|
|
@@ -118249,20 +118222,11 @@ function registerJoinCommand(program2) {
|
|
|
118249
118222
|
enableDHT: true
|
|
118250
118223
|
});
|
|
118251
118224
|
await node.start();
|
|
118252
|
-
|
|
118253
|
-
|
|
118254
|
-
|
|
118255
|
-
|
|
118256
|
-
|
|
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...");
|
|
118225
|
+
spin.succeed("Node started successfully!");
|
|
118226
|
+
info(`Peer ID: ${node.getPeerId()}`);
|
|
118227
|
+
info(`DID: ${identity3.did}`);
|
|
118228
|
+
info(`Listening on: ${node.getMultiaddrs().join(", ")}`);
|
|
118229
|
+
const connectSpin = spinner("Connecting to bootstrap peers...");
|
|
118266
118230
|
await new Promise((resolve) => {
|
|
118267
118231
|
const timeout = setTimeout(resolve, 1e4);
|
|
118268
118232
|
node.libp2p.addEventListener("peer:connect", () => {
|
|
@@ -118270,10 +118234,8 @@ function registerJoinCommand(program2) {
|
|
|
118270
118234
|
setTimeout(resolve, 500);
|
|
118271
118235
|
}, { once: true });
|
|
118272
118236
|
});
|
|
118273
|
-
|
|
118274
|
-
|
|
118275
|
-
}
|
|
118276
|
-
const cardSpin = jsonMode ? null : spinner("Publishing Agent Card to DHT...");
|
|
118237
|
+
connectSpin.succeed("Connected to network!");
|
|
118238
|
+
const cardSpin = spinner("Publishing Agent Card to DHT...");
|
|
118277
118239
|
const directAddrs = node.getMultiaddrs();
|
|
118278
118240
|
const relayAddrs = bootstrapPeers.map((relayAddr) => {
|
|
118279
118241
|
const peerId = node.getPeerId();
|
|
@@ -118294,11 +118256,7 @@ function registerJoinCommand(program2) {
|
|
|
118294
118256
|
);
|
|
118295
118257
|
const dht = createDHTOperations(node.libp2p);
|
|
118296
118258
|
await dht.publishAgentCard(signedCard);
|
|
118297
|
-
|
|
118298
|
-
cardSpin.succeed("Agent Card published!");
|
|
118299
|
-
} else {
|
|
118300
|
-
console.log(JSON.stringify({ event: "agent_card_published" }));
|
|
118301
|
-
}
|
|
118259
|
+
cardSpin.succeed("Agent Card published!");
|
|
118302
118260
|
const router = createMessageRouter(
|
|
118303
118261
|
node.libp2p,
|
|
118304
118262
|
async () => true,
|
|
@@ -118306,30 +118264,15 @@ function registerJoinCommand(program2) {
|
|
|
118306
118264
|
);
|
|
118307
118265
|
const messageHandler = async (envelope) => {
|
|
118308
118266
|
const payload = envelope.payload;
|
|
118309
|
-
|
|
118310
|
-
|
|
118311
|
-
|
|
118312
|
-
|
|
118313
|
-
|
|
118314
|
-
|
|
118315
|
-
|
|
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
|
-
}
|
|
118267
|
+
console.log();
|
|
118268
|
+
success(`>>> Received message from ${envelope.from}`);
|
|
118269
|
+
info(` Message ID: ${envelope.id}`);
|
|
118270
|
+
info(` Protocol: ${envelope.protocol}`);
|
|
118271
|
+
info(` Type: ${envelope.type}`);
|
|
118272
|
+
info(` Payload: ${JSON.stringify(payload, null, 2)}`);
|
|
118273
|
+
console.log();
|
|
118329
118274
|
if (envelope.type === "request") {
|
|
118330
|
-
|
|
118331
|
-
info(" Sending acknowledgment response...");
|
|
118332
|
-
}
|
|
118275
|
+
info(" Sending acknowledgment response...");
|
|
118333
118276
|
const { createEnvelope: createEnvelope2, signEnvelope: signEnvelope2, sign: sign2 } = await Promise.resolve().then(() => (init_dist3(), dist_exports));
|
|
118334
118277
|
const identity4 = getIdentity();
|
|
118335
118278
|
const keyPair2 = importKeyPair({
|
|
@@ -118364,38 +118307,22 @@ function registerJoinCommand(program2) {
|
|
|
118364
118307
|
router.registerHandler("/clawiverse/greet/1.0.0", messageHandler);
|
|
118365
118308
|
router.registerCatchAllHandler(messageHandler);
|
|
118366
118309
|
await router.start();
|
|
118367
|
-
|
|
118310
|
+
console.log();
|
|
118311
|
+
success("Successfully joined the Clawiverse network!");
|
|
118312
|
+
info("Listening for incoming messages...");
|
|
118313
|
+
info("Press Ctrl+C to stop");
|
|
118314
|
+
process.on("SIGINT", async () => {
|
|
118368
118315
|
console.log();
|
|
118369
|
-
|
|
118370
|
-
|
|
118371
|
-
|
|
118372
|
-
|
|
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
|
-
}
|
|
118316
|
+
const stopSpin = spinner("Stopping node...");
|
|
118317
|
+
await router.stop();
|
|
118318
|
+
await node.stop();
|
|
118319
|
+
stopSpin.succeed("Node stopped");
|
|
118387
118320
|
process.exit(0);
|
|
118388
|
-
};
|
|
118389
|
-
process.on("SIGINT", shutdown);
|
|
118390
|
-
process.on("SIGTERM", shutdown);
|
|
118321
|
+
});
|
|
118391
118322
|
await new Promise(() => {
|
|
118392
118323
|
});
|
|
118393
118324
|
} catch (err2) {
|
|
118394
|
-
|
|
118395
|
-
console.log(JSON.stringify({ error: err2.message }));
|
|
118396
|
-
} else {
|
|
118397
|
-
error(`Failed to join network: ${err2.message}`);
|
|
118398
|
-
}
|
|
118325
|
+
error(`Failed to join network: ${err2.message}`);
|
|
118399
118326
|
process.exit(1);
|
|
118400
118327
|
}
|
|
118401
118328
|
});
|
|
@@ -118698,7 +118625,7 @@ function registerCardCommand(program2) {
|
|
|
118698
118625
|
process.exit(1);
|
|
118699
118626
|
}
|
|
118700
118627
|
});
|
|
118701
|
-
card.command("edit").description("Edit Agent Card").action(async () => {
|
|
118628
|
+
card.command("edit").description("Edit Agent Card").option("--name <name>", "Agent name").option("--description <description>", "Agent description").option("--capabilities <capabilities>", "Capabilities (comma-separated)").action(async (options) => {
|
|
118702
118629
|
try {
|
|
118703
118630
|
printHeader("Edit Agent Card");
|
|
118704
118631
|
const currentCard = getAgentCard();
|
|
@@ -118706,31 +118633,40 @@ function registerCardCommand(program2) {
|
|
|
118706
118633
|
error('No Agent Card found. Run "hw1 init" first.');
|
|
118707
118634
|
process.exit(1);
|
|
118708
118635
|
}
|
|
118709
|
-
|
|
118710
|
-
|
|
118711
|
-
|
|
118712
|
-
name:
|
|
118713
|
-
|
|
118714
|
-
|
|
118715
|
-
}
|
|
118716
|
-
|
|
118717
|
-
|
|
118718
|
-
|
|
118719
|
-
|
|
118720
|
-
|
|
118721
|
-
|
|
118722
|
-
|
|
118723
|
-
|
|
118724
|
-
|
|
118725
|
-
|
|
118726
|
-
|
|
118727
|
-
|
|
118728
|
-
|
|
118729
|
-
|
|
118730
|
-
|
|
118731
|
-
|
|
118732
|
-
|
|
118733
|
-
|
|
118636
|
+
let updatedCard;
|
|
118637
|
+
if (options.name || options.description || options.capabilities) {
|
|
118638
|
+
updatedCard = {
|
|
118639
|
+
name: options.name || currentCard.name,
|
|
118640
|
+
description: options.description || currentCard.description,
|
|
118641
|
+
capabilities: options.capabilities ? options.capabilities.split(",").map((c2) => c2.trim()).filter((c2) => c2.length > 0) : currentCard.capabilities
|
|
118642
|
+
};
|
|
118643
|
+
} else {
|
|
118644
|
+
const answers = await inquirer.prompt([
|
|
118645
|
+
{
|
|
118646
|
+
type: "input",
|
|
118647
|
+
name: "name",
|
|
118648
|
+
message: "Agent name:",
|
|
118649
|
+
default: currentCard.name
|
|
118650
|
+
},
|
|
118651
|
+
{
|
|
118652
|
+
type: "input",
|
|
118653
|
+
name: "description",
|
|
118654
|
+
message: "Agent description:",
|
|
118655
|
+
default: currentCard.description
|
|
118656
|
+
},
|
|
118657
|
+
{
|
|
118658
|
+
type: "input",
|
|
118659
|
+
name: "capabilities",
|
|
118660
|
+
message: "Capabilities (comma-separated):",
|
|
118661
|
+
default: currentCard.capabilities.join(", ")
|
|
118662
|
+
}
|
|
118663
|
+
]);
|
|
118664
|
+
updatedCard = {
|
|
118665
|
+
name: answers.name,
|
|
118666
|
+
description: answers.description,
|
|
118667
|
+
capabilities: answers.capabilities.split(",").map((c2) => c2.trim()).filter((c2) => c2.length > 0)
|
|
118668
|
+
};
|
|
118669
|
+
}
|
|
118734
118670
|
setAgentCard(updatedCard);
|
|
118735
118671
|
success("Agent Card updated successfully!");
|
|
118736
118672
|
} catch (err2) {
|