wattetheria 0.3.3 → 0.3.5

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.
Files changed (3) hide show
  1. package/README.md +11 -7
  2. package/lib/cli.js +108 -11
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -556,9 +556,11 @@ Agent commands such as `identity`, `wallet`, and `servicenet` are forwarded to t
556
556
  native `wattetheria-client-cli`; installed release packages should not require Rust on the user's
557
557
  machine. The JS wrapper resolves `WATTETHERIA_CLI_BIN` first, then the matching optional native
558
558
  package such as `@wattetheria/cli-win32-x64`, then `bin/native/<platform>-<arch>/`, then `PATH`.
559
- If no host native CLI is available but the local Wattetheria node deployment is installed, the
560
- wrapper runs the same command inside the `kernel` container using the node's
561
- `/var/lib/wattetheria` data directory.
559
+ `identity` and `wallet` are lightweight local setup commands for ServiceNet publishing and wallet
560
+ binding before a local Wattetheria node is installed. If a local node deployment is already
561
+ installed, the wrapper refuses `identity` and `wallet` commands so users do not create or modify a
562
+ separate local identity or wallet outside the node. ServiceNet commands can still run through an
563
+ installed node when no host native CLI is available.
562
564
 
563
565
  NPM publish flow:
564
566
 
@@ -583,14 +585,16 @@ CLI saves the provider/card context locally:
583
585
  ```bash
584
586
  npx wattetheria servicenet agent-card init
585
587
  # or write the template into a specific directory:
586
- npx wattetheria servicenet agent-card init --out ./agents/hermes
588
+ npx wattetheria servicenet agent-card init --out <output-directory>
587
589
 
588
- npx wattetheria servicenet provider register --card ./agent-card.json
590
+ npx wattetheria servicenet register
591
+ # If the card is not in the current directory:
592
+ npx wattetheria servicenet register --card <path-to-agent-card.json>
589
593
  ```
590
594
 
591
595
  Then publish through the ServiceNet business command with the returned agent id. The publish
592
- command reads the saved provider id, ServiceNet URL, endpoint URL, and card path from local
593
- context instead of asking for repeated flags:
596
+ command reads the saved provider id, endpoint URL, and card path from local context instead of
597
+ asking for repeated flags:
594
598
 
595
599
  ```bash
596
600
  npx wattetheria servicenet publish <agent-id>
package/lib/cli.js CHANGED
@@ -73,10 +73,25 @@ Commands:
73
73
  doctor Check local prerequisites
74
74
  help Show this help
75
75
 
76
- Agent subcommands (forwarded to the bundled native CLI when available):
77
- identity init | show | export-seed
78
- wallet manage wallet payment accounts
79
- servicenet agent-card init | provider register | publish <agent-id>
76
+ Agent subcommands:
77
+ identity
78
+ init Initialize a lightweight local identity for ServiceNet publishing or wallet binding
79
+ show Show the local identity public DID and public key
80
+ export-seed Export the local identity seed; treat it like a password
81
+
82
+ wallet
83
+ create-payment-account Create a local payment account for ServiceNet payment binding
84
+ import-payment-account Import a local payment account for ServiceNet payment binding
85
+ watch-payment-account Track a payment address without importing its private key
86
+ list-payment-accounts List local payment accounts
87
+ bind-payment-account Select the active local payment account
88
+ active-payment-account Show the active local payment account
89
+
90
+ servicenet
91
+ agent-card init Generate an editable agent-card.json template in the current directory
92
+ register --card <path-to-agent-card.json>
93
+ Register the agent card and local identity with ServiceNet; returns agent_id and provider_id
94
+ publish <agent-id> Publish a registered ServiceNet agent using the agent_id returned by register
80
95
 
81
96
  Options:
82
97
  --version, -v Alias for \`version\`
@@ -94,6 +109,15 @@ Options:
94
109
  `);
95
110
  }
96
111
 
112
+ function throwCommandSuggestion(argv) {
113
+ if (argv[0] === "provider" && argv[1] === "register") {
114
+ throw new Error("Unknown command: provider register. Use `wattetheria servicenet register`.");
115
+ }
116
+ if (argv[0] === "register") {
117
+ throw new Error("Unknown command: register. Use `wattetheria servicenet register`.");
118
+ }
119
+ }
120
+
97
121
  function parseArgs(argv) {
98
122
  let command = DEFAULT_COMMAND;
99
123
  let index = 0;
@@ -1291,11 +1315,25 @@ function bundledRustBinaryPath() {
1291
1315
 
1292
1316
  function missingNativeCliError(commandName) {
1293
1317
  const platformKey = nativePlatformKey() || `${process.platform}-${process.arch}`;
1318
+ if (commandName === "identity" || commandName === "wallet") {
1319
+ return new Error(
1320
+ [
1321
+ `Cannot run '${commandName}' because the Wattetheria native CLI for ${platformKey} was not found.`,
1322
+ "",
1323
+ "`wattetheria identity` and `wattetheria wallet` are lightweight local setup commands",
1324
+ "for ServiceNet publishing and wallet binding. They do not require a local Wattetheria",
1325
+ "node, but they do require the native CLI package for this system.",
1326
+ "",
1327
+ "Install the matching Wattetheria native CLI package, then retry."
1328
+ ].join("\n")
1329
+ );
1330
+ }
1331
+
1294
1332
  const deployment = deploymentState();
1295
1333
  if (deployment.installed) {
1296
1334
  return new Error(
1297
1335
  `Wattetheria node deployment was found at ${deployment.dir}, but this npm package does not include ` +
1298
- `the native publisher CLI for ${platformKey}. ` +
1336
+ `the native CLI for ${platformKey}. ` +
1299
1337
  `Run 'npx wattetheria status' to check the installed node, or update the local node image.`
1300
1338
  );
1301
1339
  }
@@ -1306,6 +1344,59 @@ function missingNativeCliError(commandName) {
1306
1344
  );
1307
1345
  }
1308
1346
 
1347
+ function installedNodeArtifacts(deployment = deploymentState()) {
1348
+ return {
1349
+ identityPath: path.join(deployment.stateDir, "identity.json"),
1350
+ walletMetadataPath: path.join(deployment.stateDir, ".watt-wallet", "metadata.json"),
1351
+ walletKeystorePath: path.join(deployment.stateDir, ".watt-wallet", "keystore.json")
1352
+ };
1353
+ }
1354
+
1355
+ function isLightweightLocalCommand(commandName) {
1356
+ return commandName === "identity" || commandName === "wallet";
1357
+ }
1358
+
1359
+ function ensureLightweightCommandAllowed(commandName) {
1360
+ if (!isLightweightLocalCommand(commandName)) {
1361
+ return;
1362
+ }
1363
+ const deployment = deploymentState();
1364
+ if (!deployment.installed) {
1365
+ return;
1366
+ }
1367
+ const artifacts = installedNodeArtifacts(deployment);
1368
+ if (commandName === "identity") {
1369
+ throw new Error(
1370
+ [
1371
+ "Refusing to run a separate local identity command.",
1372
+ "",
1373
+ fs.existsSync(artifacts.identityPath)
1374
+ ? "A local Wattetheria node is already installed and has an identity at:"
1375
+ : "A local Wattetheria node is already installed at:",
1376
+ deployment.stateDir,
1377
+ "",
1378
+ "`wattetheria identity` is only for lightweight local setup when no Wattetheria",
1379
+ "node is installed. Use the installed node's identity instead."
1380
+ ].join("\n")
1381
+ );
1382
+ }
1383
+ if (commandName === "wallet") {
1384
+ throw new Error(
1385
+ [
1386
+ "Refusing to run a separate local wallet command.",
1387
+ "",
1388
+ fs.existsSync(artifacts.walletMetadataPath) && fs.existsSync(artifacts.walletKeystorePath)
1389
+ ? "A local Wattetheria node is already installed and has wallet state at:"
1390
+ : "A local Wattetheria node is already installed at:",
1391
+ deployment.stateDir,
1392
+ "",
1393
+ "`wattetheria wallet` is only for lightweight local setup when no Wattetheria",
1394
+ "node is installed. Use the installed node's wallet instead."
1395
+ ].join("\n")
1396
+ );
1397
+ }
1398
+ }
1399
+
1309
1400
  function forwardedArgsForInstalledNode(commandName, rawArgv) {
1310
1401
  const args = [commandName];
1311
1402
  if (!rawArgv.some((arg) => arg === "--data-dir" || arg.startsWith("--data-dir="))) {
@@ -1321,10 +1412,9 @@ function isServicenetAgentCardInit(commandName, rawArgv) {
1321
1412
  && rawArgv[2] === "init";
1322
1413
  }
1323
1414
 
1324
- function isServicenetProviderRegister(commandName, rawArgv) {
1415
+ function isServicenetRegister(commandName, rawArgv) {
1325
1416
  return commandName === "servicenet"
1326
- && rawArgv[1] === "provider"
1327
- && rawArgv[2] === "register";
1417
+ && rawArgv[1] === "register";
1328
1418
  }
1329
1419
 
1330
1420
  function isServicenetPublish(commandName, rawArgv) {
@@ -1334,7 +1424,7 @@ function isServicenetPublish(commandName, rawArgv) {
1334
1424
 
1335
1425
  function usesWorkspaceMount(commandName, rawArgv) {
1336
1426
  return isServicenetAgentCardInit(commandName, rawArgv)
1337
- || isServicenetProviderRegister(commandName, rawArgv)
1427
+ || isServicenetRegister(commandName, rawArgv)
1338
1428
  || isServicenetPublish(commandName, rawArgv);
1339
1429
  }
1340
1430
 
@@ -1416,8 +1506,8 @@ function dockerWorkspaceInvocation(commandName, rawArgv) {
1416
1506
  };
1417
1507
  }
1418
1508
 
1419
- if (isServicenetProviderRegister(commandName, rawArgv)) {
1420
- const cardArg = parsePathOption(rawArgv, "--card", 3);
1509
+ if (isServicenetRegister(commandName, rawArgv)) {
1510
+ const cardArg = parsePathOption(rawArgv, "--card", 2);
1421
1511
  if (!cardArg) {
1422
1512
  return {
1423
1513
  args: forwardedArgsForInstalledNode(commandName, rawArgv),
@@ -1536,6 +1626,8 @@ function runInstalledNodeCli(commandName, rawArgv, deployment) {
1536
1626
  }
1537
1627
 
1538
1628
  function forwardToRustBinary(commandName, rawArgv) {
1629
+ ensureLightweightCommandAllowed(commandName);
1630
+
1539
1631
  // Only the Rust binary name is allowed here. The bare `wattetheria` name
1540
1632
  // resolves to this JS shim on most user PATHs (via the npm bin link), so
1541
1633
  // including it would create an infinite spawn loop.
@@ -1562,6 +1654,9 @@ function forwardToRustBinary(commandName, rawArgv) {
1562
1654
  }
1563
1655
 
1564
1656
  const deployment = deploymentState();
1657
+ if (commandName === "identity" || commandName === "wallet") {
1658
+ throw missingNativeCliError(commandName);
1659
+ }
1565
1660
  if (deployment.runnable) {
1566
1661
  runInstalledNodeCli(commandName, rawArgv, deployment);
1567
1662
  return;
@@ -1571,6 +1666,8 @@ function forwardToRustBinary(commandName, rawArgv) {
1571
1666
  }
1572
1667
 
1573
1668
  async function run(argv) {
1669
+ throwCommandSuggestion(argv);
1670
+
1574
1671
  if (argv[0] && FORWARDED_SUBCOMMANDS.has(argv[0])) {
1575
1672
  forwardToRustBinary(argv[0], argv);
1576
1673
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wattetheria",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "description": "Wattetheria deployment CLI",
5
5
  "license": "Apache-2.0",
6
6
  "type": "commonjs",