@elisym/cli 0.33.6 → 0.34.0

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
@@ -8,6 +8,7 @@ import { isAddress, createSolanaRpc, address, signature } from '@solana/kit';
8
8
  import { generateSecretKey, getPublicKey, nip19, verifyEvent } from 'nostr-tools';
9
9
  import YAML2 from 'yaml';
10
10
  import { Command } from 'commander';
11
+ import { hexToBytes, bytesToHex } from 'nostr-tools/utils';
11
12
  import { parseSkillMd, validateSkillFrontmatter, isHostScratchError, isScriptRefusalError, startsWithRefusalHint, HostScratchError, DEFAULT_X402_MAX_INPUT_BYTES, resolveInsidePathReal, DEFAULT_SCRIPT_TIMEOUT_MS, loadSkillsFromDir, OnchainCallSkill, DynamicScriptSkill as DynamicScriptSkill$1, StaticScriptSkill as StaticScriptSkill$1, StaticFileSkill as StaticFileSkill$1, ScriptSkill as ScriptSkill$1 } from '@elisym/sdk/skills';
12
13
  import { mkdtemp, writeFile, rm, readFile, mkdir, chmod, rename, readdir, stat } from 'node:fs/promises';
13
14
  import chalk from 'chalk';
@@ -1496,6 +1497,114 @@ var init_init = __esm({
1496
1497
  init_llm();
1497
1498
  }
1498
1499
  });
1500
+ var HEX_PUBKEY_RE = /^[0-9a-f]{64}$/;
1501
+ function parseStoreOwner(value) {
1502
+ const trimmed = value.trim();
1503
+ const lowered = trimmed.toLowerCase();
1504
+ if (HEX_PUBKEY_RE.test(lowered)) {
1505
+ return lowered;
1506
+ }
1507
+ try {
1508
+ const decoded = nip19.decode(trimmed);
1509
+ if (decoded.type === "npub") {
1510
+ return decoded.data;
1511
+ }
1512
+ } catch {
1513
+ }
1514
+ throw new Error("--store must be the store owner npub (npub1...) or a 64-character hex pubkey");
1515
+ }
1516
+ async function runAskrKey(agentName, cwd, passphrase, options) {
1517
+ const loaded = await loadAgent(agentName, cwd, passphrase);
1518
+ const existing = loaded.secrets.askr_catalog_secret_key;
1519
+ const currentStore = loaded.yaml.askr_store;
1520
+ const store = options.store === void 0 ? void 0 : parseStoreOwner(options.store);
1521
+ if (options.show) {
1522
+ if (existing === void 0) {
1523
+ throw new Error(
1524
+ `Agent "${agentName}" has no Askr catalog key. Run \`elisym askr-key ${agentName} --store <owner npub>\` to create one.`
1525
+ );
1526
+ }
1527
+ if (currentStore === void 0) {
1528
+ throw new Error(
1529
+ `Agent "${agentName}" has an Askr catalog key but no store. Pass --store <owner npub> to attach it, or --rotate for a new key.`
1530
+ );
1531
+ }
1532
+ return {
1533
+ status: "existing",
1534
+ pubkey: getPublicKey(hexToBytes(existing)),
1535
+ store: currentStore
1536
+ };
1537
+ }
1538
+ if (existing !== void 0 && currentStore === void 0 && !options.rotate) {
1539
+ if (store === void 0) {
1540
+ throw new Error(
1541
+ `Agent "${agentName}" has an Askr catalog key but no store. Pass --store <owner npub> to attach it, or --rotate for a new key.`
1542
+ );
1543
+ }
1544
+ await writeYaml(loaded.dir, { ...loaded.yaml, askr_store: store });
1545
+ return { status: "attached", pubkey: getPublicKey(hexToBytes(existing)), store };
1546
+ }
1547
+ if (existing !== void 0 && currentStore !== void 0 && !options.rotate) {
1548
+ if (store !== void 0 && store !== currentStore) {
1549
+ throw new Error(
1550
+ `Agent "${agentName}" already writes another store's catalog. Use --rotate to replace its key and store.`
1551
+ );
1552
+ }
1553
+ return {
1554
+ status: "existing",
1555
+ pubkey: getPublicKey(hexToBytes(existing)),
1556
+ store: currentStore
1557
+ };
1558
+ }
1559
+ const target = store ?? currentStore;
1560
+ if (target === void 0) {
1561
+ throw new Error("--store <owner npub> is required: the store whose catalog this key writes");
1562
+ }
1563
+ const secret = bytesToHex(generateSecretKey());
1564
+ await writeSecrets(
1565
+ loaded.dir,
1566
+ { ...loaded.secrets, askr_catalog_secret_key: secret },
1567
+ passphrase
1568
+ );
1569
+ await writeYaml(loaded.dir, { ...loaded.yaml, askr_store: target });
1570
+ return {
1571
+ status: existing === void 0 ? "created" : "rotated",
1572
+ pubkey: getPublicKey(hexToBytes(secret)),
1573
+ store: target
1574
+ };
1575
+ }
1576
+ async function cmdAskrKey(agentName, options) {
1577
+ const passphrase = process.env.ELISYM_PASSPHRASE;
1578
+ let result;
1579
+ try {
1580
+ result = await runAskrKey(agentName, process.cwd(), passphrase, options);
1581
+ } catch (error) {
1582
+ console.error(error instanceof Error ? error.message : String(error));
1583
+ process.exit(1);
1584
+ }
1585
+ if (result.status === "existing" && !options.show) {
1586
+ console.log(` Agent "${agentName}" already has an Askr catalog key.`);
1587
+ } else if (result.status === "attached") {
1588
+ console.log(
1589
+ "\n Askr catalog key attached to this store.\n ! If another store authorized this key, revoke it there: what the key signs shows in every\n store that authorized it. Use --rotate for a key of its own."
1590
+ );
1591
+ } else if (result.status !== "existing") {
1592
+ console.log(
1593
+ result.status === "created" ? "\n Askr catalog key generated and saved." : "\n Askr catalog key rotated and saved. Revoke the old key in the Askr admin."
1594
+ );
1595
+ }
1596
+ console.log(` Store: ${nip19.npubEncode(result.store)}`);
1597
+ console.log(` Catalog key: ${nip19.npubEncode(result.pubkey)}`);
1598
+ console.log(` ${result.pubkey}`);
1599
+ if (result.status !== "existing") {
1600
+ console.log(
1601
+ "\n Authorize this catalog key in the Askr admin (Catalog keys), signed by the store owner.\n Until then the store refuses what it signs.\n"
1602
+ );
1603
+ }
1604
+ if (!passphrase && result.status !== "existing") {
1605
+ console.warn(" ! No passphrase set: the catalog key is stored unencrypted on disk.");
1606
+ }
1607
+ }
1499
1608
  var MAX_CONCURRENT_JOBS = 10;
1500
1609
  var RECOVERY_MAX_RETRIES = 5;
1501
1610
  var RECOVERY_INTERVAL_SECS = 60;
@@ -10951,6 +11060,13 @@ program.command("delegate-key [name]").description("Generate, show, or rotate th
10951
11060
  await cmdDelegateKey(name, options);
10952
11061
  })
10953
11062
  );
11063
+ program.command("askr-key <name>").description(
11064
+ "Generate, show, or rotate the agent's Askr catalog key for one store; prints only its pubkey"
11065
+ ).option("--store <owner>", "The store owner npub (or hex pubkey) whose catalog the key writes").option("--show", "Print the existing catalog key pubkey and store only").option("--rotate", "Replace the key (and the store, if --store names another)").action(
11066
+ safe(async (name, options) => {
11067
+ await cmdAskrKey(name, options);
11068
+ })
11069
+ );
10954
11070
  var identity = program.command("identity").description("Link, verify, and unlink external identities (GitHub, X, website)");
10955
11071
  identity.command("link <platform> [agent]").description(
10956
11072
  "Link a github|x|website identity: prints the NIP-39 proof template, verifies the proof live, writes elisym.yaml, and publishes the claim (kind 10011 / kind-0 nip05)"