@agentgates/cli 0.16.0 → 0.19.1

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 +5 -4
  2. package/dist/cli.mjs +1346 -919
  3. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -5588,7 +5588,7 @@ var require_websocket = __commonJS({
5588
5588
  var http2 = __require("http");
5589
5589
  var net = __require("net");
5590
5590
  var tls = __require("tls");
5591
- var { randomBytes: randomBytes7, createHash: createHash5 } = __require("crypto");
5591
+ var { randomBytes: randomBytes8, createHash: createHash5 } = __require("crypto");
5592
5592
  var { Duplex, Readable } = __require("stream");
5593
5593
  var { URL: URL4 } = __require("url");
5594
5594
  var PerMessageDeflate = require_permessage_deflate();
@@ -6114,7 +6114,7 @@ var require_websocket = __commonJS({
6114
6114
  }
6115
6115
  }
6116
6116
  const defaultPort = isSecure ? 443 : 80;
6117
- const key = randomBytes7(16).toString("base64");
6117
+ const key = randomBytes8(16).toString("base64");
6118
6118
  const request = isSecure ? https2.request : http2.request;
6119
6119
  const protocolSet = /* @__PURE__ */ new Set();
6120
6120
  let perMessageDeflate;
@@ -6875,7 +6875,7 @@ var require_package = __commonJS({
6875
6875
  "package.json"(exports, module) {
6876
6876
  module.exports = {
6877
6877
  name: "@agentgates/cli",
6878
- version: "0.16.0",
6878
+ version: "0.19.1",
6879
6879
  description: "Wallet operations for AI agents and humans",
6880
6880
  keywords: [
6881
6881
  "crypto",
@@ -6977,7 +6977,7 @@ var require_utils = __commonJS({
6977
6977
  exports.createHasher = createHasher;
6978
6978
  exports.createOptHasher = createOptHasher;
6979
6979
  exports.createXOFer = createXOFer;
6980
- exports.randomBytes = randomBytes7;
6980
+ exports.randomBytes = randomBytes8;
6981
6981
  var crypto_1 = require_cryptoNode();
6982
6982
  function isBytes(a) {
6983
6983
  return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
@@ -7175,7 +7175,7 @@ var require_utils = __commonJS({
7175
7175
  exports.wrapConstructor = createHasher;
7176
7176
  exports.wrapConstructorWithOpts = createOptHasher;
7177
7177
  exports.wrapXOFConstructorWithOpts = createXOFer;
7178
- function randomBytes7(bytesLength = 32) {
7178
+ function randomBytes8(bytesLength = 32) {
7179
7179
  if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === "function") {
7180
7180
  return crypto_1.crypto.getRandomValues(new Uint8Array(bytesLength));
7181
7181
  }
@@ -9347,7 +9347,7 @@ var require_edwards = __commonJS({
9347
9347
  });
9348
9348
  const { prehash } = eddsaOpts;
9349
9349
  const { BASE, Fp: Fp2, Fn } = Point2;
9350
- const randomBytes7 = eddsaOpts.randomBytes || utils_ts_1.randomBytes;
9350
+ const randomBytes8 = eddsaOpts.randomBytes || utils_ts_1.randomBytes;
9351
9351
  const adjustScalarBytes = eddsaOpts.adjustScalarBytes || ((bytes2) => bytes2);
9352
9352
  const domain = eddsaOpts.domain || ((data4, ctx2, phflag) => {
9353
9353
  (0, utils_ts_1._abool2)(phflag, "phflag");
@@ -9429,7 +9429,7 @@ var require_edwards = __commonJS({
9429
9429
  signature: 2 * _size,
9430
9430
  seed: _size
9431
9431
  };
9432
- function randomSecretKey(seed = randomBytes7(lengths.seed)) {
9432
+ function randomSecretKey(seed = randomBytes8(lengths.seed)) {
9433
9433
  return (0, utils_ts_1._abytes2)(seed, lengths.seed, "seed");
9434
9434
  }
9435
9435
  function keygen(seed) {
@@ -23937,7 +23937,7 @@ var require_websocket2 = __commonJS({
23937
23937
  var http2 = __require("http");
23938
23938
  var net = __require("net");
23939
23939
  var tls = __require("tls");
23940
- var { randomBytes: randomBytes7, createHash: createHash5 } = __require("crypto");
23940
+ var { randomBytes: randomBytes8, createHash: createHash5 } = __require("crypto");
23941
23941
  var { Duplex, Readable } = __require("stream");
23942
23942
  var { URL: URL4 } = __require("url");
23943
23943
  var PerMessageDeflate = require_permessage_deflate2();
@@ -24475,7 +24475,7 @@ var require_websocket2 = __commonJS({
24475
24475
  }
24476
24476
  }
24477
24477
  const defaultPort = isSecure ? 443 : 80;
24478
- const key = randomBytes7(16).toString("base64");
24478
+ const key = randomBytes8(16).toString("base64");
24479
24479
  const request = isSecure ? https2.request : http2.request;
24480
24480
  const protocolSet = /* @__PURE__ */ new Set();
24481
24481
  let perMessageDeflate;
@@ -28092,7 +28092,7 @@ var require_weierstrass = __commonJS({
28092
28092
  bits2int: "function",
28093
28093
  bits2int_modN: "function"
28094
28094
  });
28095
- const randomBytes7 = ecdsaOpts.randomBytes || utils_ts_1.randomBytes;
28095
+ const randomBytes8 = ecdsaOpts.randomBytes || utils_ts_1.randomBytes;
28096
28096
  const hmac2 = ecdsaOpts.hmac || ((key, ...msgs) => (0, hmac_js_1.hmac)(hash2, key, (0, utils_ts_1.concatBytes)(...msgs)));
28097
28097
  const { Fp: Fp2, Fn } = Point2;
28098
28098
  const { ORDER: CURVE_ORDER, BITS: fnBits } = Fn;
@@ -28247,7 +28247,7 @@ var require_weierstrass = __commonJS({
28247
28247
  const d = _normFnElement(Fn, privateKey);
28248
28248
  const seedArgs = [int2octets(d), int2octets(h1int)];
28249
28249
  if (extraEntropy != null && extraEntropy !== false) {
28250
- const e = extraEntropy === true ? randomBytes7(lengths.secretKey) : extraEntropy;
28250
+ const e = extraEntropy === true ? randomBytes8(lengths.secretKey) : extraEntropy;
28251
28251
  seedArgs.push((0, utils_ts_1.ensureBytes)("extraEntropy", e));
28252
28252
  }
28253
28253
  const seed = (0, utils_ts_1.concatBytes)(...seedArgs);
@@ -37870,7 +37870,7 @@ var {
37870
37870
  } = import_index.default;
37871
37871
 
37872
37872
  // src/main.ts
37873
- var import_picocolors29 = __toESM(require_picocolors(), 1);
37873
+ var import_picocolors30 = __toESM(require_picocolors(), 1);
37874
37874
 
37875
37875
  // src/commands/login.ts
37876
37876
  var import_picocolors2 = __toESM(require_picocolors(), 1);
@@ -37988,8 +37988,8 @@ async function readConfig() {
37988
37988
  }
37989
37989
  async function writeConfig(cfg) {
37990
37990
  await ensureDir();
37991
- const json = JSON.stringify(cfg, null, 2);
37992
- await fs.writeFile(configPath(), json, { mode: 384 });
37991
+ const json2 = JSON.stringify(cfg, null, 2);
37992
+ await fs.writeFile(configPath(), json2, { mode: 384 });
37993
37993
  await fs.chmod(configPath(), 384).catch(() => {
37994
37994
  });
37995
37995
  }
@@ -38847,7 +38847,7 @@ function shortAddress(addr) {
38847
38847
  }
38848
38848
 
38849
38849
  // src/commands/onboard.ts
38850
- var import_picocolors8 = __toESM(require_picocolors(), 1);
38850
+ var import_picocolors10 = __toESM(require_picocolors(), 1);
38851
38851
  import { createInterface } from "node:readline/promises";
38852
38852
 
38853
38853
  // src/lib/water.ts
@@ -39321,9 +39321,16 @@ async function emailSend() {
39321
39321
  }
39322
39322
 
39323
39323
  // src/commands/passwords.ts
39324
- var import_picocolors7 = __toESM(require_picocolors(), 1);
39324
+ var import_picocolors8 = __toESM(require_picocolors(), 1);
39325
39325
  import { readFileSync } from "node:fs";
39326
- import { randomBytes as randomBytes6 } from "node:crypto";
39326
+ import { randomBytes as randomBytes7 } from "node:crypto";
39327
+
39328
+ // src/commands/session.ts
39329
+ var import_picocolors7 = __toESM(require_picocolors(), 1);
39330
+
39331
+ // src/lib/passwords-key.ts
39332
+ import { promises as fs7 } from "node:fs";
39333
+ import * as path3 from "node:path";
39327
39334
 
39328
39335
  // node_modules/ethers/lib.esm/ethers.js
39329
39336
  var ethers_exports = {};
@@ -41769,8 +41776,8 @@ function parseEther(ether) {
41769
41776
  }
41770
41777
 
41771
41778
  // node_modules/ethers/lib.esm/utils/uuid.js
41772
- function uuidV4(randomBytes7) {
41773
- const bytes2 = getBytes(randomBytes7, "randomBytes");
41779
+ function uuidV4(randomBytes8) {
41780
+ const bytes2 = getBytes(randomBytes8, "randomBytes");
41774
41781
  bytes2[6] = bytes2[6] & 15 | 64;
41775
41782
  bytes2[8] = bytes2[8] & 63 | 128;
41776
41783
  const value = hexlify(bytes2);
@@ -44645,7 +44652,7 @@ function weierstrass(curveDef) {
44645
44652
  function prepSig(msgHash, privateKey, opts = defaultSigOpts) {
44646
44653
  if (["recovered", "canonical"].some((k) => k in opts))
44647
44654
  throw new Error("sign() legacy options not supported");
44648
- const { hash: hash2, randomBytes: randomBytes7 } = CURVE;
44655
+ const { hash: hash2, randomBytes: randomBytes8 } = CURVE;
44649
44656
  let { lowS, prehash, extraEntropy: ent } = opts;
44650
44657
  if (lowS == null)
44651
44658
  lowS = true;
@@ -44656,7 +44663,7 @@ function weierstrass(curveDef) {
44656
44663
  const d = normPrivateKeyToScalar(privateKey);
44657
44664
  const seedArgs = [int2octets(d), int2octets(h1int)];
44658
44665
  if (ent != null) {
44659
- const e = ent === true ? randomBytes7(Fp2.BYTES) : ent;
44666
+ const e = ent === true ? randomBytes8(Fp2.BYTES) : ent;
44660
44667
  seedArgs.push(ensureBytes("extraEntropy", e));
44661
44668
  }
44662
44669
  const seed = concatBytes2(...seedArgs);
@@ -61530,9 +61537,9 @@ function spelunk(object2, _path) {
61530
61537
 
61531
61538
  // node_modules/ethers/lib.esm/wallet/json-keystore.js
61532
61539
  var defaultPath = "m/44'/60'/0'/0/0";
61533
- function isKeystoreJson(json) {
61540
+ function isKeystoreJson(json2) {
61534
61541
  try {
61535
- const data4 = JSON.parse(json);
61542
+ const data4 = JSON.parse(json2);
61536
61543
  const version4 = data4.version != null ? parseInt(data4.version) : 0;
61537
61544
  if (version4 === 3) {
61538
61545
  return true;
@@ -61607,8 +61614,8 @@ function getDecryptKdfParams(data4) {
61607
61614
  }
61608
61615
  assertArgument(false, "unsupported key-derivation function", "kdf", kdf);
61609
61616
  }
61610
- function decryptKeystoreJsonSync(json, _password) {
61611
- const data4 = JSON.parse(json);
61617
+ function decryptKeystoreJsonSync(json2, _password) {
61618
+ const data4 = JSON.parse(json2);
61612
61619
  const password = getPassword(_password);
61613
61620
  const params = getDecryptKdfParams(data4);
61614
61621
  if (params.name === "pbkdf2") {
@@ -61628,8 +61635,8 @@ function stall3(duration) {
61628
61635
  }, duration);
61629
61636
  });
61630
61637
  }
61631
- async function decryptKeystoreJson(json, _password, progress) {
61632
- const data4 = JSON.parse(json);
61638
+ async function decryptKeystoreJson(json2, _password, progress) {
61639
+ const data4 = JSON.parse(json2);
61633
61640
  const password = getPassword(_password);
61634
61641
  const params = getDecryptKdfParams(data4);
61635
61642
  if (params.name === "pbkdf2") {
@@ -62178,9 +62185,9 @@ function getIndexedAccountPath(_index) {
62178
62185
  }
62179
62186
 
62180
62187
  // node_modules/ethers/lib.esm/wallet/json-crowdsale.js
62181
- function isCrowdsaleJson(json) {
62188
+ function isCrowdsaleJson(json2) {
62182
62189
  try {
62183
- const data4 = JSON.parse(json);
62190
+ const data4 = JSON.parse(json2);
62184
62191
  if (data4.encseed) {
62185
62192
  return true;
62186
62193
  }
@@ -62188,12 +62195,12 @@ function isCrowdsaleJson(json) {
62188
62195
  }
62189
62196
  return false;
62190
62197
  }
62191
- function decryptCrowdsaleJson(json, _password) {
62192
- const data4 = JSON.parse(json);
62198
+ function decryptCrowdsaleJson(json2, _password) {
62199
+ const data4 = JSON.parse(json2);
62193
62200
  const password = getPassword(_password);
62194
62201
  const address = getAddress(spelunk(data4, "ethaddr:string!"));
62195
62202
  const encseed = looseArrayify(spelunk(data4, "encseed:string!"));
62196
- assertArgument(encseed && encseed.length % 16 === 0, "invalid encseed", "json", json);
62203
+ assertArgument(encseed && encseed.length % 16 === 0, "invalid encseed", "json", json2);
62197
62204
  const key = getBytes(pbkdf2(password, password, 2e3, 32, "sha256")).slice(0, 16);
62198
62205
  const iv = encseed.slice(0, 16);
62199
62206
  const encryptedSeed = encseed.slice(16);
@@ -62275,16 +62282,16 @@ var Wallet = class _Wallet extends BaseWallet {
62275
62282
  * If %%progress%% is provided, it is called periodically during
62276
62283
  * decryption so that any UI can be updated.
62277
62284
  */
62278
- static async fromEncryptedJson(json, password, progress) {
62285
+ static async fromEncryptedJson(json2, password, progress) {
62279
62286
  let account = null;
62280
- if (isKeystoreJson(json)) {
62281
- account = await decryptKeystoreJson(json, password, progress);
62282
- } else if (isCrowdsaleJson(json)) {
62287
+ if (isKeystoreJson(json2)) {
62288
+ account = await decryptKeystoreJson(json2, password, progress);
62289
+ } else if (isCrowdsaleJson(json2)) {
62283
62290
  if (progress) {
62284
62291
  progress(0);
62285
62292
  await stall4(0);
62286
62293
  }
62287
- account = decryptCrowdsaleJson(json, password);
62294
+ account = decryptCrowdsaleJson(json2, password);
62288
62295
  if (progress) {
62289
62296
  progress(1);
62290
62297
  await stall4(0);
@@ -62299,12 +62306,12 @@ var Wallet = class _Wallet extends BaseWallet {
62299
62306
  * will lock up and freeze the UI during decryption, which may take
62300
62307
  * some time.
62301
62308
  */
62302
- static fromEncryptedJsonSync(json, password) {
62309
+ static fromEncryptedJsonSync(json2, password) {
62303
62310
  let account = null;
62304
- if (isKeystoreJson(json)) {
62305
- account = decryptKeystoreJsonSync(json, password);
62306
- } else if (isCrowdsaleJson(json)) {
62307
- account = decryptCrowdsaleJson(json, password);
62311
+ if (isKeystoreJson(json2)) {
62312
+ account = decryptKeystoreJsonSync(json2, password);
62313
+ } else if (isCrowdsaleJson(json2)) {
62314
+ account = decryptCrowdsaleJson(json2, password);
62308
62315
  } else {
62309
62316
  assertArgument(false, "invalid JSON wallet", "json", "[ REDACTED ]");
62310
62317
  }
@@ -62853,8 +62860,6 @@ var wordlists2 = {
62853
62860
  };
62854
62861
 
62855
62862
  // src/lib/passwords-key.ts
62856
- import { promises as fs7 } from "node:fs";
62857
- import * as path3 from "node:path";
62858
62863
  var SEED_PATH = "m/44'/60'/0'/0/0";
62859
62864
  var SEED_WORDS = 12;
62860
62865
  function passwordsKeyPath() {
@@ -62866,13 +62871,13 @@ function keysOf(state) {
62866
62871
  throw new Error(`${passwordsKeyPath()} is corrupt: the secret does not derive the recorded address.`);
62867
62872
  }
62868
62873
  if (state.vaultPrivateKey) {
62869
- const vaultWallet = new ethers_exports.Wallet(state.vaultPrivateKey);
62870
- if (vaultWallet.address.toLowerCase() !== String(state.vaultAddress).toLowerCase()) {
62871
- throw new Error(`${passwordsKeyPath()} is corrupt: the vault secret does not derive the recorded vault address.`);
62874
+ const olderLock = new ethers_exports.Wallet(state.vaultPrivateKey);
62875
+ if (olderLock.address.toLowerCase() !== String(state.vaultAddress).toLowerCase()) {
62876
+ throw new Error(`${passwordsKeyPath()} is corrupt: the older lock does not derive the recorded address.`);
62872
62877
  }
62873
- return { state, wallet, vaultWallet, separateLock: true };
62878
+ return { state, wallet, olderLock };
62874
62879
  }
62875
- return { state, wallet, vaultWallet: wallet, separateLock: false };
62880
+ return { state, wallet };
62876
62881
  }
62877
62882
  async function loadPasswordsKey() {
62878
62883
  let raw;
@@ -62904,20 +62909,15 @@ function normaliseSeed(raw, what = "a seed") {
62904
62909
  if (!ethers_exports.Mnemonic.isValidMnemonic(phrase)) throw new Error(`${what}: those are not twelve words from the wordlist, or the last one does not check out.`);
62905
62910
  return phrase;
62906
62911
  }
62907
- function nodeOf(phrase) {
62908
- return ethers_exports.HDNodeWallet.fromPhrase(phrase, void 0, SEED_PATH);
62909
- }
62910
- function stateOf(signing, vault) {
62911
- const s = nodeOf(signing);
62912
- const v = vault ? nodeOf(vault) : null;
62912
+ function stateOf(phrase) {
62913
+ const node = ethers_exports.HDNodeWallet.fromPhrase(phrase, void 0, SEED_PATH);
62913
62914
  return {
62914
- version: 3,
62915
+ version: 2,
62915
62916
  family: "evm",
62916
- address: s.address,
62917
- privateKey: s.privateKey,
62918
- mnemonic: signing,
62917
+ address: node.address,
62918
+ privateKey: node.privateKey,
62919
+ mnemonic: phrase,
62919
62920
  path: SEED_PATH,
62920
- ...v ? { vaultMnemonic: vault, vaultAddress: v.address, vaultPrivateKey: v.privateKey } : {},
62921
62921
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
62922
62922
  };
62923
62923
  }
@@ -62930,32 +62930,20 @@ async function loadOrCreatePasswordsKey() {
62930
62930
  const existing = await loadPasswordsKey();
62931
62931
  if (existing) return { ...existing, created: false };
62932
62932
  const seed = mintPhrase();
62933
- const vaultSeed = mintPhrase();
62934
- const state = stateOf(seed, vaultSeed);
62933
+ const state = stateOf(seed);
62935
62934
  await writeKey(state);
62936
- return { ...keysOf(state), created: true, minted: { seed, vaultSeed } };
62935
+ return { ...keysOf(state), created: true, minted: { seed } };
62937
62936
  }
62938
62937
  async function importPasswordsSeed(args) {
62939
- const seed = args.seed ? normaliseSeed(args.seed, "--seed") : null;
62940
- const vaultSeed = args.vaultSeed ? normaliseSeed(args.vaultSeed, "--vault-seed") : null;
62941
- if (!seed && !vaultSeed) throw new Error("bring twelve words with --seed, and the vault's twelve with --vault-seed.");
62938
+ const seed = normaliseSeed(args.seed, "--seed");
62942
62939
  const existing = await loadPasswordsKey();
62943
- if (!seed) {
62944
- if (!existing?.state.mnemonic) throw new Error("--vault-seed alone needs a signing key here already: run init, or bring --seed with it.");
62945
- if (existing.state.vaultMnemonic && existing.state.vaultMnemonic !== vaultSeed && !args.replace) {
62946
- throw new Error(`this key already has vault words (${existing.state.vaultAddress}); pass --replace to overwrite them. Rows sealed under the old ones open only under the old ones.`);
62947
- }
62948
- const state2 = stateOf(existing.state.mnemonic, vaultSeed);
62949
- await writeKey(state2);
62950
- return keysOf(state2);
62951
- }
62952
62940
  if (existing && !args.replace) {
62953
- if (existing.state.mnemonic === seed && (!vaultSeed || existing.state.vaultMnemonic === vaultSeed)) return existing;
62941
+ if (existing.state.mnemonic === seed) return existing;
62954
62942
  throw new Error(
62955
62943
  `a passwords key already exists at ${passwordsKeyPath()} (${existing.state.address}); pass --replace to overwrite it. The old key is the only thing that opens the rows it sealed.`
62956
62944
  );
62957
62945
  }
62958
- const state = stateOf(seed, vaultSeed);
62946
+ const state = stateOf(seed);
62959
62947
  await writeKey(state);
62960
62948
  return keysOf(state);
62961
62949
  }
@@ -62983,17 +62971,424 @@ async function importPasswordsKey(privateKeyHex, replace) {
62983
62971
  }
62984
62972
  async function requirePasswordsKey() {
62985
62973
  const fromEnv = (process.env.AGENTGATES_PASSWORDS_SEED || "").trim();
62986
- if (fromEnv) {
62987
- const vaultEnv = (process.env.AGENTGATES_PASSWORDS_VAULT_SEED || "").trim();
62988
- return keysOf(stateOf(normaliseSeed(fromEnv, "AGENTGATES_PASSWORDS_SEED"), vaultEnv ? normaliseSeed(vaultEnv, "AGENTGATES_PASSWORDS_VAULT_SEED") : null));
62989
- }
62974
+ if (fromEnv) return keysOf(stateOf(normaliseSeed(fromEnv, "AGENTGATES_PASSWORDS_SEED")));
62990
62975
  const existing = await loadPasswordsKey();
62991
62976
  if (!existing) throw new Error("no passwords key on this machine yet: run `agentgates passwords init` first, or set AGENTGATES_PASSWORDS_SEED to twelve words.");
62992
62977
  return existing;
62993
62978
  }
62994
62979
 
62980
+ // src/lib/session-bridge.ts
62981
+ import { createServer } from "node:http";
62982
+ import { randomBytes as randomBytes5 } from "node:crypto";
62983
+
62984
+ // src/lib/passwords-wire.ts
62985
+ import { randomBytes as randomBytes4 } from "node:crypto";
62986
+ var trim2 = (v) => v ? v.replace(/\/$/, "") : "";
62987
+ function identityOrigin() {
62988
+ return trim2(process.env.AGENTGATES_IDENTITY_ORIGIN) || trim2(process.env.AGENTGATES_ORIGIN) || "https://agentgates.ai";
62989
+ }
62990
+ function siteOrigin() {
62991
+ return trim2(process.env.AGENTGATES_ORIGIN) || "https://agentgates.ai";
62992
+ }
62993
+ var LANE = "/api/identity";
62994
+ var WireError = class extends Error {
62995
+ constructor(status3, code, message, body) {
62996
+ super(message);
62997
+ this.status = status3;
62998
+ this.code = code;
62999
+ this.body = body;
63000
+ this.name = "WireError";
63001
+ }
63002
+ status;
63003
+ code;
63004
+ body;
63005
+ };
63006
+ async function ownerAuthHeader(wallet, method, path6) {
63007
+ const timestamp = Math.floor(Date.now() / 1e3);
63008
+ const nonce = randomBytes4(16).toString("hex");
63009
+ const signature = await wallet.signMessage(`${method.toUpperCase()}
63010
+ ${path6}
63011
+ ${nonce}
63012
+ ${timestamp}`);
63013
+ return Buffer.from(JSON.stringify({ address: wallet.address, timestamp, nonce, signature })).toString("base64");
63014
+ }
63015
+ async function signedFetch(wallet, method, path6, body, timeoutMs = 13e4) {
63016
+ const headers = {
63017
+ accept: "application/json",
63018
+ "user-agent": CLI_USER_AGENT,
63019
+ "x-wallet-auth": await ownerAuthHeader(wallet, method, path6)
63020
+ };
63021
+ if (body !== void 0) headers["content-type"] = "application/json";
63022
+ let res;
63023
+ try {
63024
+ res = await fetch(`${identityOrigin()}${path6}`, {
63025
+ method,
63026
+ headers,
63027
+ body: body !== void 0 ? JSON.stringify(body) : void 0,
63028
+ signal: AbortSignal.timeout(timeoutMs)
63029
+ });
63030
+ } catch (err) {
63031
+ throw new WireError(0, "network_error", `could not reach ${identityOrigin()}: ${err.message}`, null);
63032
+ }
63033
+ const text = await res.text();
63034
+ let json2 = null;
63035
+ try {
63036
+ json2 = text ? JSON.parse(text) : null;
63037
+ } catch {
63038
+ json2 = null;
63039
+ }
63040
+ return { status: res.status, body: json2, text };
63041
+ }
63042
+ function expectOk(answer, what) {
63043
+ if (answer.status >= 200 && answer.status < 300 && answer.body) return answer.body;
63044
+ const b2 = answer.body ?? {};
63045
+ const code = typeof b2.code === "string" ? b2.code : null;
63046
+ const error = typeof b2.error === "string" ? b2.error : `${what}: HTTP ${answer.status}`;
63047
+ throw new WireError(answer.status, code, error, answer.body);
63048
+ }
63049
+ async function readAttestation() {
63050
+ let res;
63051
+ try {
63052
+ res = await fetch(`${identityOrigin()}${LANE}/passwords/attestation`, {
63053
+ headers: { accept: "application/json", "user-agent": CLI_USER_AGENT },
63054
+ signal: AbortSignal.timeout(6e4)
63055
+ });
63056
+ } catch (err) {
63057
+ throw new WireError(0, "network_error", `could not reach ${identityOrigin()}: ${err.message}`, null);
63058
+ }
63059
+ const body = await res.json().catch(() => null);
63060
+ if (!res.ok || !body?.publicKey || !body?.keyId) {
63061
+ const error = body?.error ?? `the box's key could not be read: HTTP ${res.status}`;
63062
+ throw new WireError(res.status, body?.code ?? null, error, body);
63063
+ }
63064
+ return body;
63065
+ }
63066
+ async function listRows(wallet) {
63067
+ const out = expectOk(await signedFetch(wallet, "GET", `${LANE}/passwords`), "list");
63068
+ return { passwords: out.passwords ?? [], permitted: out.permitted ?? [] };
63069
+ }
63070
+ async function storeRow(wallet, body) {
63071
+ const out = expectOk(await signedFetch(wallet, "POST", `${LANE}/passwords`, body), "store");
63072
+ return out.password;
63073
+ }
63074
+ async function revealRow(wallet, id2) {
63075
+ const out = expectOk(await signedFetch(wallet, "POST", `${LANE}/passwords/${encodeURIComponent(id2)}/reveal`), "reveal");
63076
+ return out.passkeyBlob;
63077
+ }
63078
+ async function postPermit(wallet, signed2) {
63079
+ const out = expectOk(
63080
+ await signedFetch(wallet, "POST", `${LANE}/passwords/permits`, { typedData: signed2.typedData, signature: signed2.signature }),
63081
+ "permit"
63082
+ );
63083
+ return out.permit;
63084
+ }
63085
+ async function postUse(wallet, id2, body, timeoutMs = 2e5) {
63086
+ return signedFetch(wallet, "POST", `${LANE}/passwords/${encodeURIComponent(id2)}/use`, body, timeoutMs);
63087
+ }
63088
+ async function withdrawInvite(wallet, envelope, signature) {
63089
+ return expectOk(
63090
+ await signedFetch(wallet, "POST", `${LANE}/passwords/invites/withdraw`, { invite: { envelope, signature } }),
63091
+ "withdraw"
63092
+ );
63093
+ }
63094
+
63095
+ // src/lib/session-bridge.ts
63096
+ var BRIDGE_FRAGMENT_KEY = "agentgates-open";
63097
+ var CODE_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
63098
+ function mintToken() {
63099
+ return randomBytes5(16).toString("hex");
63100
+ }
63101
+ function mintCode() {
63102
+ const bytes2 = randomBytes5(6);
63103
+ let out = "";
63104
+ for (let i = 0; i < 6; i++) out += CODE_ALPHABET[bytes2[i] % CODE_ALPHABET.length];
63105
+ return `${out.slice(0, 3)}-${out.slice(3)}`;
63106
+ }
63107
+ function openUrl(port, token) {
63108
+ return `http://127.0.0.1:${port}/open?token=${token}`;
63109
+ }
63110
+ function siteOpenUrl(origin, port, token) {
63111
+ return `${origin}/#${BRIDGE_FRAGMENT_KEY}=${port}.${token}`;
63112
+ }
63113
+ function readBody(req, limit = 4096) {
63114
+ return new Promise((resolve2, reject) => {
63115
+ let data4 = "";
63116
+ req.on("data", (chunk) => {
63117
+ data4 += chunk;
63118
+ if (data4.length > limit) {
63119
+ reject(new Error("body too large"));
63120
+ req.destroy();
63121
+ }
63122
+ });
63123
+ req.on("end", () => resolve2(data4));
63124
+ req.on("error", reject);
63125
+ });
63126
+ }
63127
+ function json(res, status3, body) {
63128
+ res.writeHead(status3, { "content-type": "application/json", "cache-control": "no-store" });
63129
+ res.end(JSON.stringify(body));
63130
+ }
63131
+ function html(res, status3, body) {
63132
+ res.writeHead(status3, {
63133
+ "content-type": "text/html; charset=utf-8",
63134
+ "cache-control": "no-store",
63135
+ "referrer-policy": "no-referrer",
63136
+ "x-frame-options": "DENY",
63137
+ "content-security-policy": "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; connect-src 'self'; form-action 'none'"
63138
+ });
63139
+ res.end(body);
63140
+ }
63141
+ var esc = (s) => s.replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);
63142
+ var PAGE_STYLE = "body{margin:0;background:#101216;color:#f2f3f5;font:15px/1.5 ui-sans-serif,system-ui,sans-serif;display:grid;place-items:center;min-height:100vh}main{max-width:440px;padding:28px;border:1px solid rgba(255,255,255,.09);border-radius:16px;background:#1a1c21}h1{font-size:20px;margin:0 0 8px}p{color:rgba(242,243,245,.6);margin:8px 0}code{font-family:ui-monospace,Menlo,monospace;color:#fff}button{margin-top:14px;height:40px;padding:0 16px;border:0;border-radius:11px;background:#0891b2;color:#fff;font:inherit;font-weight:650;cursor:pointer}button:disabled{opacity:.5;cursor:default}.ok{color:#4ade80}";
63143
+ function openPage(args) {
63144
+ const short2 = `${args.address.slice(0, 6)}\u2026${args.address.slice(-4)}`;
63145
+ const site = siteOpenUrl(args.origin, args.port, args.token);
63146
+ return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Agentgates \xB7 continue as ${esc(short2)}</title><style>${PAGE_STYLE}</style></head><body><main>
63147
+ <h1>Continue as <code>${esc(short2)}</code></h1>
63148
+ <p>Your agent is handing you its session on agentgates.ai. Nothing leaves this machine: the words cross from this page to the site's window and nowhere else.</p>
63149
+ <button id="go" type="button">Continue to agentgates.ai</button>
63150
+ <p id="line"></p>
63151
+ <script>
63152
+ (function(){
63153
+ var ORIGIN=${JSON.stringify(args.origin)}, TOKEN=${JSON.stringify(args.token)}, WORDS=${JSON.stringify(args.words)}, ADDRESS=${JSON.stringify(args.address)}, SITE=${JSON.stringify(site)};
63154
+ var go=document.getElementById('go'), line=document.getElementById('line'), w=null, done=false;
63155
+ window.addEventListener('message',function(e){
63156
+ if(done||e.origin!==ORIGIN||!e.data||e.data.type!=='agentgates-open-ready'||e.data.token!==TOKEN)return;
63157
+ var target=w||e.source; if(!target)return;
63158
+ target.postMessage({type:'agentgates-open-words',token:TOKEN,words:WORDS,address:ADDRESS},ORIGIN);
63159
+ done=true; WORDS='';
63160
+ fetch('/taken?token='+encodeURIComponent(TOKEN),{cache:'no-store'}).catch(function(){});
63161
+ line.className='ok'; line.textContent='Handed over. You can close this tab.';
63162
+ go.disabled=true; setTimeout(function(){window.close();},1500);
63163
+ });
63164
+ go.addEventListener('click',function(){
63165
+ w=window.open(SITE,'_blank'); if(!w){line.textContent='The browser blocked the new tab; allow pop-ups for 127.0.0.1 and press again.';return;}
63166
+ go.disabled=true; line.textContent='Waiting for agentgates.ai to say it is ready\u2026';
63167
+ setTimeout(function(){ if(!done){ go.disabled=false; line.textContent='The site did not answer; press again.'; } },20000);
63168
+ });
63169
+ })();
63170
+ </script></main></body></html>`;
63171
+ }
63172
+ function receivePage(args) {
63173
+ return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Agentgates \xB7 receiving</title><style>${PAGE_STYLE}</style></head><body><main>
63174
+ <h1>Receiving your session</h1>
63175
+ <p id="line">Waiting for agentgates.ai to hand the words over\u2026</p>
63176
+ <script>
63177
+ (function(){
63178
+ var ORIGIN=${JSON.stringify(args.origin)}, line=document.getElementById('line'), done=false;
63179
+ window.addEventListener('message',function(e){
63180
+ if(done||e.origin!==ORIGIN||!e.data||e.data.type!=='agentgates-receive-words')return;
63181
+ done=true;
63182
+ fetch('/receive',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({code:e.data.code,words:e.data.words})})
63183
+ .then(function(r){return r.json().then(function(b){return {ok:r.ok&&b.ok===true,error:b.error};});})
63184
+ .catch(function(){return {ok:false,error:'the agent did not take it'};})
63185
+ .then(function(out){
63186
+ if(e.source)e.source.postMessage({type:'agentgates-receive-done',ok:out.ok,error:out.error||null},ORIGIN);
63187
+ line.className=out.ok?'ok':''; line.textContent=out.ok?'Handed over. Your agent is this account now. This tab closes itself.':('Not taken: '+(out.error||'unknown'));
63188
+ if(out.ok)setTimeout(function(){window.close();},1200); else done=false;
63189
+ });
63190
+ });
63191
+ if(window.opener)window.opener.postMessage({type:'agentgates-receive-ready'},ORIGIN);
63192
+ else line.textContent='Open this from agentgates.ai: Top up \u2192 Hand this session to my agent.';
63193
+ })();
63194
+ </script></main></body></html>`;
63195
+ }
63196
+ async function listen(server) {
63197
+ await new Promise((resolve2, reject) => {
63198
+ server.once("error", reject);
63199
+ server.listen(0, "127.0.0.1", () => resolve2());
63200
+ });
63201
+ const addr = server.address();
63202
+ if (!addr || typeof addr === "string") throw new Error("listener has no port");
63203
+ return addr.port;
63204
+ }
63205
+ async function serveWordsOnce(args) {
63206
+ const token = mintToken();
63207
+ let served = false;
63208
+ let taken = false;
63209
+ let port = 0;
63210
+ let done = () => {
63211
+ };
63212
+ let fail3 = () => {
63213
+ };
63214
+ const settled = new Promise((resolve2, reject) => {
63215
+ done = resolve2;
63216
+ fail3 = reject;
63217
+ });
63218
+ const server = createServer((req, res) => {
63219
+ const url = new URL(req.url ?? "/", "http://127.0.0.1");
63220
+ if (req.method === "GET" && url.pathname === "/open") {
63221
+ if (served || url.searchParams.get("token") !== token) return html(res, 403, `<!doctype html><html><head><meta charset="utf-8"><style>${PAGE_STYLE}</style></head><body><main><h1>This link was already used</h1><p>Run <code>agentgates open</code> again for a fresh one.</p></main></body></html>`);
63222
+ served = true;
63223
+ return html(res, 200, openPage({ origin: siteOrigin(), port, token, words: args.words, address: args.address }));
63224
+ }
63225
+ if (req.method === "GET" && url.pathname === "/taken") {
63226
+ if (taken || url.searchParams.get("token") !== token) return json(res, 403, { error: "token spent or wrong" });
63227
+ taken = true;
63228
+ json(res, 200, { ok: true });
63229
+ setTimeout(() => {
63230
+ server.close();
63231
+ done();
63232
+ }, 50);
63233
+ return;
63234
+ }
63235
+ return json(res, 404, { error: "not found" });
63236
+ });
63237
+ port = await listen(server);
63238
+ args.onUrl(openUrl(port, token), port);
63239
+ const timer = setTimeout(() => {
63240
+ if (!taken) {
63241
+ server.close();
63242
+ fail3(new Error(`nobody took the session in ${Math.round(args.waitMs / 1e3)}s`));
63243
+ }
63244
+ }, args.waitMs);
63245
+ try {
63246
+ await settled;
63247
+ } finally {
63248
+ clearTimeout(timer);
63249
+ }
63250
+ }
63251
+ async function receiveWordsOnce(args) {
63252
+ const code = mintCode();
63253
+ let taken = false;
63254
+ let done = () => {
63255
+ };
63256
+ let fail3 = () => {
63257
+ };
63258
+ const settled = new Promise((resolve2, reject) => {
63259
+ done = resolve2;
63260
+ fail3 = reject;
63261
+ });
63262
+ const server = createServer(async (req, res) => {
63263
+ const url = new URL(req.url ?? "/", "http://127.0.0.1");
63264
+ if (req.method === "GET" && url.pathname === "/receive") return html(res, 200, receivePage({ origin: siteOrigin() }));
63265
+ if (req.method === "GET" && url.pathname === "/hello") return json(res, 200, { ok: true, receive: true });
63266
+ if (req.method !== "POST" || url.pathname !== "/receive") return json(res, 404, { error: "not found" });
63267
+ const origin = req.headers.origin;
63268
+ if (origin && origin !== `http://127.0.0.1:${server.address().port}`) return json(res, 403, { error: "origin not allowed" });
63269
+ let body;
63270
+ try {
63271
+ body = JSON.parse(await readBody(req));
63272
+ } catch {
63273
+ return json(res, 400, { error: "body must be JSON" });
63274
+ }
63275
+ if (taken || typeof body.code !== "string" || body.code.trim().toUpperCase() !== code) return json(res, 403, { error: "code spent or wrong" });
63276
+ const words7 = typeof body.words === "string" ? body.words.trim().toLowerCase().split(/\s+/).join(" ") : "";
63277
+ if (words7.split(" ").length !== 12) return json(res, 400, { error: "twelve words expected" });
63278
+ taken = true;
63279
+ json(res, 200, { ok: true });
63280
+ setTimeout(() => {
63281
+ server.close();
63282
+ done({ words: words7 });
63283
+ }, 1500);
63284
+ });
63285
+ const port = await listen(server);
63286
+ args.onCode(code, port);
63287
+ const timer = setTimeout(() => {
63288
+ if (!taken) {
63289
+ server.close();
63290
+ fail3(new Error(`nobody handed a session over in ${Math.round(args.waitMs / 1e3)}s`));
63291
+ }
63292
+ }, args.waitMs);
63293
+ try {
63294
+ return await settled;
63295
+ } finally {
63296
+ clearTimeout(timer);
63297
+ }
63298
+ }
63299
+ function handoffCode(code, port) {
63300
+ return `${code}-${port}`;
63301
+ }
63302
+
63303
+ // src/commands/session.ts
63304
+ var jsonMode = (opts) => opts.json === true || !process.stdout.isTTY;
63305
+ function refuse(opts, error, code = null) {
63306
+ if (jsonMode(opts)) process.stdout.write(JSON.stringify({ ok: false, code, error }, null, 2) + "\n");
63307
+ else process.stderr.write(` ${error}${code ? import_picocolors7.default.dim(` (${code})`) : ""}
63308
+ `);
63309
+ process.exit(1);
63310
+ }
63311
+ function humanHandoffLines(address) {
63312
+ const site = siteOrigin();
63313
+ return ` ${import_picocolors7.default.bold("For your human")}
63314
+ ${import_picocolors7.default.dim(`Log in as this account at ${site}: Log in \u2192 I have a seed \u2192 paste the twelve words.`)}
63315
+ ${import_picocolors7.default.dim(`Or hand it over live on this machine: agentgates open (opens the browser already logged in as ${address.slice(0, 6)}\u2026${address.slice(-4)})`)}
63316
+ `;
63317
+ }
63318
+ async function sessionOpen(opts) {
63319
+ const waitMs = Math.max(10, Number(opts.wait) || 300) * 1e3;
63320
+ let keys;
63321
+ try {
63322
+ keys = await requirePasswordsKey();
63323
+ } catch (err) {
63324
+ return refuse(opts, err.message, "no_key");
63325
+ }
63326
+ const words7 = keys.state.mnemonic;
63327
+ if (!words7) return refuse(opts, "this key was made without words (a bare key); only a twelve-word account can be handed to a browser. Mint one with init --replace.", "bare_key");
63328
+ const address = keys.wallet.address;
63329
+ try {
63330
+ await serveWordsOnce({
63331
+ words: words7,
63332
+ address,
63333
+ waitMs,
63334
+ onUrl: (url, port) => {
63335
+ if (jsonMode(opts)) {
63336
+ process.stdout.write(JSON.stringify({ ok: true, status: "waiting", url, port, address, waitSeconds: waitMs / 1e3 }) + "\n");
63337
+ } else {
63338
+ process.stdout.write(`
63339
+ ${import_picocolors7.default.bold("OPEN")} ${import_picocolors7.default.dim(`a page from this machine; press Continue there and the browser is ${address}`)}
63340
+ `);
63341
+ if (opts.printUrl || opts.browser === false) process.stdout.write(` ${import_picocolors7.default.cyan(url)}
63342
+ `);
63343
+ process.stdout.write(` ${import_picocolors7.default.dim(`waiting ${Math.round(waitMs / 1e3)}s; the page is served once and the link dies with it`)}
63344
+ `);
63345
+ }
63346
+ if (opts.browser !== false && !process.env.CI) void open_default(url).catch(() => {
63347
+ });
63348
+ }
63349
+ });
63350
+ if (jsonMode(opts)) process.stdout.write(JSON.stringify({ ok: true, status: "handed", address }) + "\n");
63351
+ else process.stdout.write(` ${import_picocolors7.default.green("\u2713")} handed over; the browser is this account now.
63352
+
63353
+ `);
63354
+ } catch (err) {
63355
+ return refuse(opts, err.message, "not_taken");
63356
+ }
63357
+ }
63358
+ async function sessionReceive(opts) {
63359
+ const waitMs = Math.max(10, Number(opts.wait) || 300) * 1e3;
63360
+ try {
63361
+ const { words: words7 } = await receiveWordsOnce({
63362
+ waitMs,
63363
+ onCode: (code, port) => {
63364
+ const typed = handoffCode(code, port);
63365
+ if (jsonMode(opts)) {
63366
+ process.stdout.write(JSON.stringify({ ok: true, status: "waiting", code: typed, port, waitSeconds: waitMs / 1e3 }) + "\n");
63367
+ } else {
63368
+ process.stdout.write(`
63369
+ ${import_picocolors7.default.bold("RECEIVE")} ${import_picocolors7.default.dim(`on ${siteOrigin()}: Top up \u2192 Hand this session to my agent, then type`)}
63370
+ `);
63371
+ process.stdout.write(` ${import_picocolors7.default.cyan(typed)}
63372
+ `);
63373
+ process.stdout.write(` ${import_picocolors7.default.dim(`waiting ${Math.round(waitMs / 1e3)}s; the code dies on first use`)}
63374
+ `);
63375
+ }
63376
+ }
63377
+ });
63378
+ const { state } = await importPasswordsSeed({ seed: words7, replace: opts.replace === true });
63379
+ if (jsonMode(opts)) process.stdout.write(JSON.stringify({ ok: true, status: "received", address: state.address, path: passwordsKeyPath() }) + "\n");
63380
+ else process.stdout.write(` ${import_picocolors7.default.green("\u2713")} this CLI is ${import_picocolors7.default.bold(state.address)} now
63381
+ ${import_picocolors7.default.dim(passwordsKeyPath())}
63382
+
63383
+ `);
63384
+ } catch (err) {
63385
+ const message = err.message;
63386
+ return refuse(opts, message, /already exists/.test(message) ? "key_exists" : "not_received");
63387
+ }
63388
+ }
63389
+
62995
63390
  // src/lib/passwords-seal.ts
62996
- import { createCipheriv, createDecipheriv, createECDH, createHash as createHash2, hkdfSync, randomBytes as randomBytes4, randomUUID } from "node:crypto";
63391
+ import { createCipheriv, createDecipheriv, createECDH, createHash as createHash2, hkdfSync, randomBytes as randomBytes6, randomUUID } from "node:crypto";
62997
63392
  var PASSWORDS_SUITE = "AGENTGATES-PASSWORDS-ECDH-P256-HKDF-SHA256-AESGCM-v1";
62998
63393
  var PASSWORDS_WIRE_VERSION = 1;
62999
63394
  var INFO_BLOB = "blob";
@@ -63135,7 +63530,7 @@ function vaultAesKeyFromSignature(signature, kdf = KDF_CURRENT) {
63135
63530
  }
63136
63531
  function sealDurable(plaintext, signature, address) {
63137
63532
  const aesKey = vaultAesKeyFromSignature(signature, KDF_CURRENT);
63138
- const iv = randomBytes4(IV_BYTES);
63533
+ const iv = randomBytes6(IV_BYTES);
63139
63534
  const c = createCipheriv("aes-256-gcm", aesKey, iv);
63140
63535
  const ct = Buffer.concat([c.update(plaintext), c.final(), c.getAuthTag()]);
63141
63536
  const sealed = {
@@ -63180,7 +63575,7 @@ function sealToBox(boxPublicKeyRaw, keyId, payloadJson, secretId, owner) {
63180
63575
  eph.generateKeys();
63181
63576
  const shared = eph.computeSecret(boxPublicKeyRaw);
63182
63577
  const aesKey = Buffer.from(hkdfSync("sha256", shared, Buffer.from(keyId, "utf8"), Buffer.from(`${PASSWORDS_SUITE}|${INFO_BLOB}`, "utf8"), 32));
63183
- const iv = randomBytes4(IV_BYTES);
63578
+ const iv = randomBytes6(IV_BYTES);
63184
63579
  const cipher = createCipheriv("aes-256-gcm", aesKey, iv);
63185
63580
  cipher.setAAD(blobAad(keyId, secretId, owner));
63186
63581
  const ct = Buffer.concat([cipher.update(Buffer.from(payloadJson, "utf8")), cipher.final(), cipher.getAuthTag()]);
@@ -63243,7 +63638,7 @@ function validatePermitRequest(owner, m, nowSeconds = Math.floor(Date.now() / 1e
63243
63638
  }
63244
63639
  async function signPermit(wallet, request) {
63245
63640
  const fields = validatePermitRequest(wallet.address, request);
63246
- const nonce = ethers_exports.hexlify(randomBytes4(32));
63641
+ const nonce = ethers_exports.hexlify(randomBytes6(32));
63247
63642
  const message = {
63248
63643
  owner: ethers_exports.getAddress(fields.owner),
63249
63644
  agent: ethers_exports.getAddress(fields.agent),
@@ -63290,7 +63685,7 @@ function capsuleKey(secret, nonce, rowId) {
63290
63685
  return Buffer.from(hkdfSync("sha256", secret, Buffer.from(INVITE_HKDF_SALT, "utf8"), Buffer.from(`capsule|${nonce}|${rowId}`, "utf8"), 32));
63291
63686
  }
63292
63687
  function sealCapsule(secret, nonce, rowId, payloadJson) {
63293
- const iv = randomBytes4(IV_BYTES);
63688
+ const iv = randomBytes6(IV_BYTES);
63294
63689
  const c = createCipheriv("aes-256-gcm", capsuleKey(secret, nonce, rowId), iv);
63295
63690
  c.setAAD(Buffer.from(`${nonce}|${rowId}`, "utf8"));
63296
63691
  const ct = Buffer.concat([c.update(Buffer.from(payloadJson, "utf8")), c.final(), c.getAuthTag()]);
@@ -63329,140 +63724,29 @@ function decodeInviteFragment(fragment) {
63329
63724
  return { envelope: parsed.envelope, signature: parsed.signature, secret: fromB64u(parsed.s) };
63330
63725
  }
63331
63726
 
63332
- // src/lib/passwords-wire.ts
63333
- import { randomBytes as randomBytes5 } from "node:crypto";
63334
- var trim2 = (v) => v ? v.replace(/\/$/, "") : "";
63335
- function identityOrigin() {
63336
- return trim2(process.env.AGENTGATES_IDENTITY_ORIGIN) || trim2(process.env.AGENTGATES_ORIGIN) || "https://agentgates.ai";
63337
- }
63338
- function siteOrigin() {
63339
- return trim2(process.env.AGENTGATES_ORIGIN) || "https://agentgates.ai";
63340
- }
63341
- var LANE = "/api/identity";
63342
- var WireError = class extends Error {
63343
- constructor(status3, code, message, body) {
63344
- super(message);
63345
- this.status = status3;
63346
- this.code = code;
63347
- this.body = body;
63348
- this.name = "WireError";
63349
- }
63350
- status;
63351
- code;
63352
- body;
63353
- };
63354
- async function ownerAuthHeader(wallet, method, path6) {
63355
- const timestamp = Math.floor(Date.now() / 1e3);
63356
- const nonce = randomBytes5(16).toString("hex");
63357
- const signature = await wallet.signMessage(`${method.toUpperCase()}
63358
- ${path6}
63359
- ${nonce}
63360
- ${timestamp}`);
63361
- return Buffer.from(JSON.stringify({ address: wallet.address, timestamp, nonce, signature })).toString("base64");
63362
- }
63363
- async function signedFetch(wallet, method, path6, body, timeoutMs = 13e4) {
63364
- const headers = {
63365
- accept: "application/json",
63366
- "user-agent": CLI_USER_AGENT,
63367
- "x-wallet-auth": await ownerAuthHeader(wallet, method, path6)
63368
- };
63369
- if (body !== void 0) headers["content-type"] = "application/json";
63370
- let res;
63371
- try {
63372
- res = await fetch(`${identityOrigin()}${path6}`, {
63373
- method,
63374
- headers,
63375
- body: body !== void 0 ? JSON.stringify(body) : void 0,
63376
- signal: AbortSignal.timeout(timeoutMs)
63377
- });
63378
- } catch (err) {
63379
- throw new WireError(0, "network_error", `could not reach ${identityOrigin()}: ${err.message}`, null);
63380
- }
63381
- const text = await res.text();
63382
- let json = null;
63383
- try {
63384
- json = text ? JSON.parse(text) : null;
63385
- } catch {
63386
- json = null;
63387
- }
63388
- return { status: res.status, body: json, text };
63389
- }
63390
- function expectOk(answer, what) {
63391
- if (answer.status >= 200 && answer.status < 300 && answer.body) return answer.body;
63392
- const b2 = answer.body ?? {};
63393
- const code = typeof b2.code === "string" ? b2.code : null;
63394
- const error = typeof b2.error === "string" ? b2.error : `${what}: HTTP ${answer.status}`;
63395
- throw new WireError(answer.status, code, error, answer.body);
63396
- }
63397
- async function readAttestation() {
63398
- let res;
63399
- try {
63400
- res = await fetch(`${identityOrigin()}${LANE}/passwords/attestation`, {
63401
- headers: { accept: "application/json", "user-agent": CLI_USER_AGENT },
63402
- signal: AbortSignal.timeout(6e4)
63403
- });
63404
- } catch (err) {
63405
- throw new WireError(0, "network_error", `could not reach ${identityOrigin()}: ${err.message}`, null);
63406
- }
63407
- const body = await res.json().catch(() => null);
63408
- if (!res.ok || !body?.publicKey || !body?.keyId) {
63409
- const error = body?.error ?? `the box's key could not be read: HTTP ${res.status}`;
63410
- throw new WireError(res.status, body?.code ?? null, error, body);
63411
- }
63412
- return body;
63413
- }
63414
- async function listRows(wallet) {
63415
- const out = expectOk(await signedFetch(wallet, "GET", `${LANE}/passwords`), "list");
63416
- return { passwords: out.passwords ?? [], permitted: out.permitted ?? [] };
63417
- }
63418
- async function storeRow(wallet, body) {
63419
- const out = expectOk(await signedFetch(wallet, "POST", `${LANE}/passwords`, body), "store");
63420
- return out.password;
63421
- }
63422
- async function revealRow(wallet, id2) {
63423
- const out = expectOk(await signedFetch(wallet, "POST", `${LANE}/passwords/${encodeURIComponent(id2)}/reveal`), "reveal");
63424
- return out.passkeyBlob;
63425
- }
63426
- async function postPermit(wallet, signed2) {
63427
- const out = expectOk(
63428
- await signedFetch(wallet, "POST", `${LANE}/passwords/permits`, { typedData: signed2.typedData, signature: signed2.signature }),
63429
- "permit"
63430
- );
63431
- return out.permit;
63432
- }
63433
- async function postUse(wallet, id2, body, timeoutMs = 2e5) {
63434
- return signedFetch(wallet, "POST", `${LANE}/passwords/${encodeURIComponent(id2)}/use`, body, timeoutMs);
63435
- }
63436
- async function withdrawInvite(wallet, envelope, signature) {
63437
- return expectOk(
63438
- await signedFetch(wallet, "POST", `${LANE}/passwords/invites/withdraw`, { invite: { envelope, signature } }),
63439
- "withdraw"
63440
- );
63441
- }
63442
-
63443
63727
  // src/commands/passwords.ts
63444
63728
  var SITE5 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
63445
- var jsonMode = (opts) => opts.json === true || !process.stdout.isTTY;
63729
+ var jsonMode2 = (opts) => opts.json === true || !process.stdout.isTTY;
63446
63730
  function emit2(opts, data4, human) {
63447
- if (jsonMode(opts)) {
63731
+ if (jsonMode2(opts)) {
63448
63732
  process.stdout.write(JSON.stringify(data4, null, 2) + "\n");
63449
63733
  return;
63450
63734
  }
63451
63735
  human();
63452
63736
  }
63453
- function refuse(opts, error, code, extra = {}) {
63454
- if (jsonMode(opts)) {
63737
+ function refuse2(opts, error, code, extra = {}) {
63738
+ if (jsonMode2(opts)) {
63455
63739
  process.stdout.write(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
63456
63740
  } else {
63457
- process.stderr.write(` ${error}${code ? import_picocolors7.default.dim(` (${code})`) : ""}
63741
+ process.stderr.write(` ${error}${code ? import_picocolors8.default.dim(` (${code})`) : ""}
63458
63742
  `);
63459
63743
  }
63460
63744
  process.exit(1);
63461
63745
  }
63462
63746
  function failFrom(opts, err) {
63463
- if (err instanceof WireError) return refuse(opts, err.message, err.code, { status: err.status });
63464
- if (err instanceof PasswordsSealError) return refuse(opts, err.message, "refused");
63465
- return refuse(opts, err.message ?? String(err), null);
63747
+ if (err instanceof WireError) return refuse2(opts, err.message, err.code, { status: err.status });
63748
+ if (err instanceof PasswordsSealError) return refuse2(opts, err.message, "refused");
63749
+ return refuse2(opts, err.message ?? String(err), null);
63466
63750
  }
63467
63751
  var short = (addr) => `${addr.slice(0, 6)}\u2026${addr.slice(-4)}`;
63468
63752
  var splitList = (v) => (v ?? "").split(",").map((s) => s.trim()).filter(Boolean);
@@ -63514,19 +63798,20 @@ async function passwordsPricing(opts) {
63514
63798
  return;
63515
63799
  }
63516
63800
  if (!product || product.available === false) {
63517
- process.stdout.write(` ${import_picocolors7.default.dim(product?.note || product?.brief || "Passwords are not on sale right now.")}
63801
+ process.stdout.write(` ${import_picocolors8.default.dim(product?.note || product?.brief || "Passwords are not on sale right now.")}
63518
63802
  `);
63519
63803
  process.exitCode = 1;
63520
63804
  return;
63521
63805
  }
63522
63806
  process.stdout.write(`
63523
- ${import_picocolors7.default.bold("PASSWORDS")} ${import_picocolors7.default.dim(product.brief || "logins your agent uses and never sees")}
63807
+ ${import_picocolors8.default.bold("PASSWORDS")} ${import_picocolors8.default.dim(product.brief || "logins your agent uses and never sees")}
63524
63808
 
63525
63809
  `);
63526
63810
  const freeRows = slice.payg?.passwords;
63811
+ const freeUses = slice.payg?.passwordsUsesPerDay ?? 0;
63527
63812
  if (freeRows) {
63528
63813
  process.stdout.write(
63529
- ` ${import_picocolors7.default.bold("free".padEnd(11))} ${import_picocolors7.default.cyan("$0".padStart(4))}${"".padEnd(11)} ${import_picocolors7.default.dim(`${freeRows} passwords, every use metered`)}
63814
+ ` ${import_picocolors8.default.bold("free".padEnd(11))} ${import_picocolors8.default.cyan("$0".padStart(4))}${"".padEnd(11)} ${import_picocolors8.default.dim(`${freeRows} login${freeRows === 1 ? "" : "s"}, ${freeUses > 0 ? `${freeUses} uses a day` : "every use metered"}; try it first`)}
63530
63815
  `
63531
63816
  );
63532
63817
  }
@@ -63543,16 +63828,16 @@ async function passwordsPricing(opts) {
63543
63828
  }
63544
63829
  for (const f2 of families) {
63545
63830
  const rows = byFamily.get(f2).sort((a, b2) => a.units - b2.units);
63546
- const cells = rows.map((p) => `${import_picocolors7.default.cyan(usd4(p.priceUsd).padStart(4))}${import_picocolors7.default.dim(`/${p.units} days`.padEnd(10))}`).join(" ");
63831
+ const cells = rows.map((p) => `${import_picocolors8.default.cyan(usd4(p.priceUsd).padStart(4))}${import_picocolors8.default.dim(`/${p.units} days`.padEnd(10))}`).join(" ");
63547
63832
  const lead = rows[0];
63548
63833
  const cap = [
63549
63834
  lead.passwords ? `${lead.passwords.toLocaleString()} passwords` : "",
63550
63835
  lead.usesPerDay ? `${lead.usesPerDay.toLocaleString()} uses/day` : ""
63551
63836
  ].filter(Boolean).join(" \xB7 ");
63552
- process.stdout.write(` ${import_picocolors7.default.bold(f2.padEnd(11))} ${cells} ${import_picocolors7.default.dim(cap)}
63837
+ process.stdout.write(` ${import_picocolors8.default.bold(f2.padEnd(11))} ${cells} ${import_picocolors8.default.dim(cap)}
63553
63838
  `);
63554
63839
  }
63555
- if (plans.length === 0) process.stdout.write(` ${import_picocolors7.default.dim("no plan rungs are priced right now")}
63840
+ if (plans.length === 0) process.stdout.write(` ${import_picocolors8.default.dim("no plan rungs are priced right now")}
63556
63841
  `);
63557
63842
  const use = slice.passwordsUsage?.useUsd;
63558
63843
  const login2 = slice.passwordsUsage?.loginUsd;
@@ -63561,16 +63846,16 @@ async function passwordsPricing(opts) {
63561
63846
  login2 ? `a login ${usd4(login2)}` : ""
63562
63847
  ].filter(Boolean).join(" \xB7 ");
63563
63848
  if (meter) process.stdout.write(`
63564
- ${import_picocolors7.default.dim(`past the daily uses, from the agent's prepaid balance: ${meter}`)}
63849
+ ${import_picocolors8.default.dim(`past the daily uses, from the agent's prepaid balance: ${meter}`)}
63565
63850
  `);
63566
- process.stdout.write(` ${import_picocolors7.default.dim("storing is free on every plan; we store ciphertext we cannot read")}
63851
+ process.stdout.write(` ${import_picocolors8.default.dim("storing is free on every plan; we store ciphertext we cannot read")}
63567
63852
  `);
63568
63853
  const bal = slice.balance;
63569
- if (bal?.note) process.stdout.write(` ${import_picocolors7.default.dim(bal.note)}
63854
+ if (bal?.note) process.stdout.write(` ${import_picocolors8.default.dim(bal.note)}
63570
63855
  `);
63571
63856
  const nets = [...new Set((plans[0]?.byNetwork ?? []).map((n2) => n2.network))];
63572
63857
  if (nets.length) process.stdout.write(`
63573
- ${import_picocolors7.default.dim(`USDC on ${nets.join(", ")}`)}
63858
+ ${import_picocolors8.default.dim(`USDC on ${nets.join(", ")}`)}
63574
63859
 
63575
63860
  `);
63576
63861
  else process.stdout.write("\n");
@@ -63581,60 +63866,53 @@ async function passwordsInit(opts) {
63581
63866
  const { state: state2 } = await importPasswordsKey(opts.import, opts.replace === true);
63582
63867
  emit2(opts, { ok: true, address: state2.address, created: false, imported: true, path: passwordsKeyPath() }, () => {
63583
63868
  process.stdout.write(`
63584
- ${import_picocolors7.default.green("\u2713")} key imported: ${import_picocolors7.default.bold(state2.address)}
63585
- ${import_picocolors7.default.dim(passwordsKeyPath())}
63869
+ ${import_picocolors8.default.green("\u2713")} key imported: ${import_picocolors8.default.bold(state2.address)}
63870
+ ${import_picocolors8.default.dim(passwordsKeyPath())}
63586
63871
 
63587
63872
  `);
63588
63873
  });
63589
63874
  return;
63590
63875
  }
63591
- if (opts.seed || opts.vaultSeed) {
63592
- const { state: state2, separateLock: separateLock2 } = await importPasswordsSeed({ seed: opts.seed, vaultSeed: opts.vaultSeed, replace: opts.replace === true });
63593
- emit2(opts, { ok: true, address: state2.address, vaultAddress: separateLock2 ? state2.vaultAddress : null, created: false, imported: true, words: SEED_WORDS, path: passwordsKeyPath() }, () => {
63594
- process.stdout.write(
63595
- `
63596
- ${import_picocolors7.default.green("\u2713")} twelve words taken: ${import_picocolors7.default.bold(state2.address)}` + (separateLock2 ? `
63597
- ${import_picocolors7.default.dim("the vault's twelve too, lock")} ${state2.vaultAddress}` : `
63598
- ${import_picocolors7.default.dim("no vault words: this key is its own lock")}`) + `
63599
- ${import_picocolors7.default.dim(passwordsKeyPath())}
63876
+ if (opts.seed) {
63877
+ const { state: state2 } = await importPasswordsSeed({ seed: opts.seed, replace: opts.replace === true });
63878
+ emit2(opts, { ok: true, address: state2.address, created: false, imported: true, words: SEED_WORDS, path: passwordsKeyPath() }, () => {
63879
+ process.stdout.write(`
63880
+ ${import_picocolors8.default.green("\u2713")} twelve words taken: ${import_picocolors8.default.bold(state2.address)}
63881
+ ${import_picocolors8.default.dim(passwordsKeyPath())}
63600
63882
 
63601
- `
63602
- );
63883
+ `);
63603
63884
  });
63604
63885
  return;
63605
63886
  }
63606
63887
  if (opts.revealSeed) {
63607
- const { state: state2, separateLock: separateLock2 } = await requirePasswordsKey();
63888
+ const { state: state2 } = await requirePasswordsKey();
63608
63889
  if (!state2.mnemonic) throw new Error("this key was made without words (a bare key); mint a new one with init --replace, or bring words with init --seed.");
63609
- emit2(opts, { ok: true, address: state2.address, seed: state2.mnemonic, ...separateLock2 ? { vaultAddress: state2.vaultAddress, vaultSeed: state2.vaultMnemonic } : {} }, () => {
63610
- process.stdout.write(
63611
- `
63612
- ${import_picocolors7.default.dim("signing")} ${state2.mnemonic}
63613
- ` + (separateLock2 ? ` ${import_picocolors7.default.dim("vault")} ${state2.vaultMnemonic}
63614
- ` : "") + `
63615
- ${import_picocolors7.default.dim(`the words behind ${state2.address}. Whoever holds the signing words is this account; whoever holds the vault words opens what it stores.`)}
63890
+ emit2(opts, { ok: true, address: state2.address, seed: state2.mnemonic }, () => {
63891
+ process.stdout.write(`
63892
+ ${state2.mnemonic}
63616
63893
 
63617
- `
63618
- );
63894
+ ${import_picocolors8.default.dim(`the words behind ${state2.address}. Whoever holds them is this account: they sign every call, hold its balance and open what it stores.`)}
63895
+
63896
+ ` + humanHandoffLines(state2.address) + "\n");
63619
63897
  });
63620
63898
  return;
63621
63899
  }
63622
- const { state, created, minted, separateLock } = await loadOrCreatePasswordsKey();
63623
- emit2(opts, { ok: true, address: state.address, vaultAddress: separateLock ? state.vaultAddress : null, created, path: passwordsKeyPath(), ...minted ? { seed: minted.seed, vaultSeed: minted.vaultSeed } : {} }, () => {
63900
+ const { state, created, minted } = await loadOrCreatePasswordsKey();
63901
+ emit2(opts, { ok: true, address: state.address, created, path: passwordsKeyPath(), ...minted ? { seed: minted.seed } : {} }, () => {
63624
63902
  process.stdout.write(
63625
63903
  `
63626
- ${import_picocolors7.default.green("\u2713")} ${created ? "keys minted" : "keys already here"}: ${import_picocolors7.default.bold(state.address)}
63627
- ${import_picocolors7.default.dim(passwordsKeyPath())}
63904
+ ${import_picocolors8.default.green("\u2713")} ${created ? "key minted" : "key already here"}: ${import_picocolors8.default.bold(state.address)}
63905
+ ${import_picocolors8.default.dim(passwordsKeyPath())}
63628
63906
  ` + (minted ? `
63629
- ${import_picocolors7.default.dim("signing")} ${import_picocolors7.default.bold(minted.seed)}
63630
- ${import_picocolors7.default.dim("vault")} ${import_picocolors7.default.bold(minted.vaultSeed)}
63907
+ ${import_picocolors8.default.bold(minted.seed)}
63631
63908
 
63632
- ${import_picocolors7.default.dim("Shown once. The signing words are this account on agentgates.ai; the vault words open what it stores. Write both down, or hand them to the person you work for.")}
63633
- ${import_picocolors7.default.dim("agentgates passwords init --reveal-seed \xB7 prints them again")}
63909
+ ${import_picocolors8.default.dim("Shown once. These twelve words are this account on agentgates.ai: they sign every call, hold its balance and open what it stores. Write them down, or hand them to the person you work for.")}
63910
+ ${import_picocolors8.default.dim("agentgates init --reveal-seed \xB7 prints them again")}
63634
63911
 
63635
- ` : ` ${import_picocolors7.default.dim(separateLock ? "The signing key signs every call; the vault key locks what it stores. Neither leaves this machine." : "It signs every call and locks your vault. It never leaves this machine.")}
63912
+ ` + humanHandoffLines(state.address) + "\n" : ` ${import_picocolors8.default.dim("It signs every call, holds this account's balance and locks its vault. It never leaves this machine.")}
63636
63913
 
63637
- `) + ` ${import_picocolors7.default.dim("agentgates passwords add --label <name> --host <site> --username <u> --password <p>")}
63914
+ `) + ` ${import_picocolors8.default.dim("agentgates browser balance \xB7 the balance and the address that tops it up")}
63915
+ ${import_picocolors8.default.dim("agentgates passwords add --label <name> --host <site> --username <u> --password <p>")}
63638
63916
 
63639
63917
  `
63640
63918
  );
@@ -63645,7 +63923,7 @@ async function passwordsInit(opts) {
63645
63923
  }
63646
63924
  async function passwordsAdd(opts) {
63647
63925
  try {
63648
- const { wallet, vaultWallet } = await requirePasswordsKey();
63926
+ const { wallet } = await requirePasswordsKey();
63649
63927
  const label = (opts.label ?? "").trim().slice(0, MAX_LABEL_CHARS);
63650
63928
  if (!label) throw new PasswordsSealError("--label names the login (what you will call it)");
63651
63929
  const hosts = [...opts.host ?? [], ...splitList(opts.hosts)];
@@ -63668,8 +63946,8 @@ async function passwordsAdd(opts) {
63668
63946
  const att = await readAttestation();
63669
63947
  const id2 = mintSecretId();
63670
63948
  const payloadJson = JSON.stringify(payload);
63671
- const signature = await signVaultMessage(vaultWallet);
63672
- const passkeyBlob = sealDurable(Buffer.from(payloadJson, "utf8"), signature, vaultWallet.address);
63949
+ const signature = await signVaultMessage(wallet);
63950
+ const passkeyBlob = sealDurable(Buffer.from(payloadJson, "utf8"), signature, wallet.address);
63673
63951
  const cvmBlob = sealToBox(Buffer.from(att.publicKey, "base64url"), att.keyId, payloadJson, id2, wallet.address);
63674
63952
  const row = await storeRow(wallet, {
63675
63953
  id: id2,
@@ -63677,7 +63955,7 @@ async function passwordsAdd(opts) {
63677
63955
  kind: payload.kind,
63678
63956
  hosts: payload.hosts,
63679
63957
  ...username ? { username } : {},
63680
- credentialId: `wallet:${vaultWallet.address.toLowerCase()}`,
63958
+ credentialId: `wallet:${wallet.address.toLowerCase()}`,
63681
63959
  passkeyBlob,
63682
63960
  cvmBlob,
63683
63961
  cvmKeyId: att.keyId
@@ -63685,12 +63963,12 @@ async function passwordsAdd(opts) {
63685
63963
  emit2(opts, { ok: true, id: row.id, label: row.label, kind: row.kind, hosts: row.hosts, username: row.username ?? null, owner: wallet.address }, () => {
63686
63964
  process.stdout.write(
63687
63965
  `
63688
- ${import_picocolors7.default.green("\u2713")} stored ${import_picocolors7.default.bold(row.label)} for ${row.hosts.join(", ")}
63689
- ${import_picocolors7.default.dim("row")} ${row.id}
63690
- ${import_picocolors7.default.dim("sealed on this machine; the server holds ciphertext it cannot open")}
63966
+ ${import_picocolors8.default.green("\u2713")} stored ${import_picocolors8.default.bold(row.label)} for ${row.hosts.join(", ")}
63967
+ ${import_picocolors8.default.dim("row")} ${row.id}
63968
+ ${import_picocolors8.default.dim("sealed on this machine; the server holds ciphertext it cannot open")}
63691
63969
 
63692
- ${import_picocolors7.default.dim(`agentgates passwords allow \xB7 permit yourself to use it`)}
63693
- ${import_picocolors7.default.dim(`agentgates passwords use --row ${row.id} --url https://${row.hosts[0]}/login`)}
63970
+ ${import_picocolors8.default.dim(`agentgates passwords allow \xB7 permit yourself to use it`)}
63971
+ ${import_picocolors8.default.dim(`agentgates passwords use --row ${row.id} --url https://${row.hosts[0]}/login`)}
63694
63972
 
63695
63973
  `
63696
63974
  );
@@ -63721,9 +63999,9 @@ async function passwordsAllow(opts) {
63721
63999
  emit2(opts, { ok: true, permitId: permit.id, agent: permit.agent, self: self2, secretIds: permit.secretIds, hosts: permit.hosts, uses: permit.uses, usesPerDay: permit.usesPerDay, approveEachUse: permit.approveEachUse, expiresAt: permit.expiresAt }, () => {
63722
64000
  process.stdout.write(
63723
64001
  `
63724
- ${import_picocolors7.default.green("\u2713")} ${self2 ? "you may use" : `${short(permit.agent)} may use`} ${permit.secretIds[0] === "*" ? "every login this key holds" : `${permit.secretIds.length} login${permit.secretIds.length === 1 ? "" : "s"}`} for ${permit.uses.join(", ")} until ${permit.expiresAt.slice(0, 10)}
63725
- ${import_picocolors7.default.dim("permit")} ${permit.id}
63726
- ` + (permit.approveEachUse ? ` ${import_picocolors7.default.dim(self2 ? "ask-me is on for a permit to yourself, which parks every use behind your own board; nobody is there to press approve" : "every use waits for the owner's signature")}
64002
+ ${import_picocolors8.default.green("\u2713")} ${self2 ? "you may use" : `${short(permit.agent)} may use`} ${permit.secretIds[0] === "*" ? "every login this key holds" : `${permit.secretIds.length} login${permit.secretIds.length === 1 ? "" : "s"}`} for ${permit.uses.join(", ")} until ${permit.expiresAt.slice(0, 10)}
64003
+ ${import_picocolors8.default.dim("permit")} ${permit.id}
64004
+ ` + (permit.approveEachUse ? ` ${import_picocolors8.default.dim(self2 ? "ask-me is on for a permit to yourself, which parks every use behind your own board; nobody is there to press approve" : "every use waits for the owner's signature")}
63727
64005
  ` : "") + "\n"
63728
64006
  );
63729
64007
  });
@@ -63737,25 +64015,25 @@ async function passwordsList(opts) {
63737
64015
  const { passwords: passwords2, permitted } = await listRows(wallet);
63738
64016
  emit2(opts, { ok: true, address: wallet.address, passwords: passwords2, permitted }, () => {
63739
64017
  process.stdout.write(`
63740
- ${import_picocolors7.default.bold(short(wallet.address))}
64018
+ ${import_picocolors8.default.bold(short(wallet.address))}
63741
64019
 
63742
64020
  `);
63743
64021
  if (passwords2.length === 0 && permitted.length === 0) {
63744
- process.stdout.write(` ${import_picocolors7.default.dim("nothing stored and nothing permitted yet")}
64022
+ process.stdout.write(` ${import_picocolors8.default.dim("nothing stored and nothing permitted yet")}
63745
64023
 
63746
64024
  `);
63747
64025
  return;
63748
64026
  }
63749
64027
  if (passwords2.length) {
63750
- process.stdout.write(` ${import_picocolors7.default.dim("yours")}
64028
+ process.stdout.write(` ${import_picocolors8.default.dim("yours")}
63751
64029
  `);
63752
- for (const r of passwords2) process.stdout.write(` ${import_picocolors7.default.cyan(r.id.padEnd(40))} ${r.label.padEnd(24)} ${import_picocolors7.default.dim(r.hosts.join(", "))}${r.stale ? import_picocolors7.default.dim(" (stale: re-seal on the board)") : ""}
64030
+ for (const r of passwords2) process.stdout.write(` ${import_picocolors8.default.cyan(r.id.padEnd(40))} ${r.label.padEnd(24)} ${import_picocolors8.default.dim(r.hosts.join(", "))}${r.stale ? import_picocolors8.default.dim(" (stale: re-seal on the board)") : ""}
63753
64031
  `);
63754
64032
  }
63755
64033
  if (permitted.length) {
63756
- process.stdout.write(` ${import_picocolors7.default.dim("permitted to you")}
64034
+ process.stdout.write(` ${import_picocolors8.default.dim("permitted to you")}
63757
64035
  `);
63758
- for (const r of permitted) process.stdout.write(` ${import_picocolors7.default.cyan(r.id.padEnd(40))} ${r.label.padEnd(24)} ${import_picocolors7.default.dim(`${r.hosts.join(", ")} \xB7 ${r.uses.join(", ")}`)}
64036
+ for (const r of permitted) process.stdout.write(` ${import_picocolors8.default.cyan(r.id.padEnd(40))} ${r.label.padEnd(24)} ${import_picocolors8.default.dim(`${r.hosts.join(", ")} \xB7 ${r.uses.join(", ")}`)}
63759
64037
  `);
63760
64038
  }
63761
64039
  process.stdout.write("\n");
@@ -63787,20 +64065,20 @@ function printUseAnswer(opts, status3, body) {
63787
64065
  const code = typeof result.code === "string" ? result.code : "ok";
63788
64066
  const digest = typeof result.digest === "string" ? result.digest : "";
63789
64067
  process.stdout.write(`
63790
- ${import_picocolors7.default.green("\u2713")} ${code}${body.seconds ? import_picocolors7.default.dim(` ${body.seconds}s`) : ""}${body.chargedUsd && body.chargedUsd !== "0.00" ? import_picocolors7.default.dim(` $${body.chargedUsd}`) : ""}
64068
+ ${import_picocolors8.default.green("\u2713")} ${code}${body.seconds ? import_picocolors8.default.dim(` ${body.seconds}s`) : ""}${body.chargedUsd && body.chargedUsd !== "0.00" ? import_picocolors8.default.dim(` $${body.chargedUsd}`) : ""}
63791
64069
  `);
63792
64070
  if (digest) process.stdout.write(`
63793
64071
  ${digest.split("\n").map((l) => ` ${l}`).join("\n")}
63794
64072
  `);
63795
64073
  const steps = Array.isArray(result.steps) ? result.steps : [];
63796
- for (const s of steps) process.stdout.write(` ${import_picocolors7.default.dim(JSON.stringify(s).slice(0, 200))}
64074
+ for (const s of steps) process.stdout.write(` ${import_picocolors8.default.dim(JSON.stringify(s).slice(0, 200))}
63797
64075
  `);
63798
64076
  process.stdout.write("\n");
63799
64077
  return;
63800
64078
  }
63801
64079
  process.stdout.write(`
63802
- ${body.error ?? `HTTP ${status3}`}${body.code ? import_picocolors7.default.dim(` (${body.code})`) : ""}
63803
- ${body.useId ? ` ${import_picocolors7.default.dim("use")} ${body.useId}
64080
+ ${body.error ?? `HTTP ${status3}`}${body.code ? import_picocolors8.default.dim(` (${body.code})`) : ""}
64081
+ ${body.useId ? ` ${import_picocolors8.default.dim("use")} ${body.useId}
63804
64082
  ` : ""}
63805
64083
  `);
63806
64084
  });
@@ -63840,7 +64118,7 @@ async function passwordsUse(opts) {
63840
64118
  waitCap !== null ? startedAt + waitCap * 1e3 : Number.POSITIVE_INFINITY
63841
64119
  );
63842
64120
  if (Date.now() >= deadline) break;
63843
- if (!jsonMode(opts)) process.stderr.write(` ${import_picocolors7.default.dim(body2.error ?? "waiting for the owner")}
64121
+ if (!jsonMode2(opts)) process.stderr.write(` ${import_picocolors8.default.dim(body2.error ?? "waiting for the owner")}
63844
64122
  `);
63845
64123
  answer = await postUse(wallet, rowId, { use, request: use === "totp" && Object.keys(request).length === 0 ? void 0 : request, useId: body2.useId, wait: 25 });
63846
64124
  }
@@ -63856,7 +64134,7 @@ function joinPath() {
63856
64134
  }
63857
64135
  async function passwordsInvite(opts) {
63858
64136
  try {
63859
- const { wallet, vaultWallet, separateLock } = await requirePasswordsKey();
64137
+ const { wallet, olderLock } = await requirePasswordsKey();
63860
64138
  if (opts.withdraw) {
63861
64139
  const hash2 = opts.withdraw.includes("#") ? opts.withdraw.slice(opts.withdraw.indexOf("#")) : opts.withdraw;
63862
64140
  const { envelope: envelope2, signature } = decodeInviteFragment(hash2);
@@ -63864,7 +64142,7 @@ async function passwordsInvite(opts) {
63864
64142
  const out = await withdrawInvite(wallet, envelope2, signature);
63865
64143
  emit2(opts, { ok: true, withdrawn: true, nonce: out.nonce }, () => {
63866
64144
  process.stdout.write(`
63867
- ${import_picocolors7.default.green("\u2713")} withdrawn; that link opens nothing now
64145
+ ${import_picocolors8.default.green("\u2713")} withdrawn; that link opens nothing now
63868
64146
 
63869
64147
  `);
63870
64148
  });
@@ -63878,10 +64156,10 @@ async function passwordsInvite(opts) {
63878
64156
  if (wanted.length === 0) throw new PasswordsSealError("this key holds no logins to hand over; add one first");
63879
64157
  if (wanted.length > MAX_SECRET_IDS_PER_PERMIT) throw new PasswordsSealError(`an invitation carries at most ${MAX_SECRET_IDS_PER_PERMIT} logins`);
63880
64158
  const rows = [];
63881
- const secret = randomBytes6(32);
63882
- const nonce = ethers_exports.hexlify(randomBytes6(32));
63883
- const locks = [await signVaultMessage(vaultWallet)];
63884
- if (separateLock) locks.push(await signVaultMessage(wallet));
64159
+ const secret = randomBytes7(32);
64160
+ const nonce = ethers_exports.hexlify(randomBytes7(32));
64161
+ const locks = [await signVaultMessage(wallet)];
64162
+ if (olderLock) locks.push(await signVaultMessage(olderLock));
63885
64163
  for (const id2 of wanted) {
63886
64164
  const row = passwords2.find((r) => r.id === id2);
63887
64165
  if (!row) throw new PasswordsSealError(`${id2} is not a row this key holds`);
@@ -63894,7 +64172,7 @@ async function passwordsInvite(opts) {
63894
64172
  } catch {
63895
64173
  }
63896
64174
  }
63897
- if (payloadJson === null) throw new PasswordsSealError(`${id2} is locked with words this key does not hold`);
64175
+ if (payloadJson === null) throw new PasswordsSealError(`${id2} is locked with a key this machine does not hold`);
63898
64176
  parseSecretPayload(payloadJson);
63899
64177
  rows.push({
63900
64178
  id: row.id,
@@ -63921,13 +64199,13 @@ async function passwordsInvite(opts) {
63921
64199
  emit2(opts, { ok: true, link, agent: envelope.agent, rows: rows.map((r) => ({ id: r.id, label: r.label })), expiresAt: new Date(envelope.expiresAt * 1e3).toISOString(), minutes }, () => {
63922
64200
  process.stdout.write(
63923
64201
  `
63924
- ${import_picocolors7.default.green("\u2713")} an invitation over ${rows.length} login${rows.length === 1 ? "" : "s"}, good for ${minutes} minutes
64202
+ ${import_picocolors8.default.green("\u2713")} an invitation over ${rows.length} login${rows.length === 1 ? "" : "s"}, good for ${minutes} minutes
63925
64203
 
63926
64204
  ${link}
63927
64205
 
63928
- ${import_picocolors7.default.dim("Whoever opens it takes the owner seat over these logins and sets the guardrails.")}
63929
- ${import_picocolors7.default.dim("The link is the key to them until it is used. Send it to one person, once.")}
63930
- ${import_picocolors7.default.dim("agentgates passwords invite --withdraw '<link>' \xB7 if it went to the wrong place")}
64206
+ ${import_picocolors8.default.dim("Whoever opens it takes these logins under their own wallet and sets the guardrails.")}
64207
+ ${import_picocolors8.default.dim("The link is the key to them until it is used. Send it to one person, once.")}
64208
+ ${import_picocolors8.default.dim("agentgates passwords invite --withdraw '<link>' \xB7 if it went to the wrong place")}
63931
64209
 
63932
64210
  `
63933
64211
  );
@@ -63937,279 +64215,6 @@ async function passwordsInvite(opts) {
63937
64215
  }
63938
64216
  }
63939
64217
 
63940
- // src/commands/onboard.ts
63941
- var WORDMARK = [
63942
- " _ _",
63943
- " __ _ __ _ ___ _ _| |_ __ _ __ _| |_ ___ ___",
63944
- " / _` / _` / -_) ' \\ _/ _` / _` | _/ -_|_-<",
63945
- " \\__,_\\__, \\___|_||_\\__\\__, \\__,_|\\__\\___/__/",
63946
- " |___/ |___/"
63947
- ].join("\n");
63948
- var TAGLINE = "Confidential virtual machines, inference, phone numbers and email, paid per use in USDC.";
63949
- var { version: LOCAL_VERSION } = require_package();
63950
- function olderThan(a, b2) {
63951
- const pa = a.split(".").map(Number);
63952
- const pb = b2.split(".").map(Number);
63953
- for (let i = 0; i < 3; i++) {
63954
- if ((pa[i] ?? 0) < (pb[i] ?? 0)) return true;
63955
- if ((pa[i] ?? 0) > (pb[i] ?? 0)) return false;
63956
- }
63957
- return false;
63958
- }
63959
- async function staleLine() {
63960
- try {
63961
- const ctl = new AbortController();
63962
- const timer = setTimeout(() => ctl.abort(), 900);
63963
- const res = await fetch("https://registry.npmjs.org/@agentgates/cli/latest", {
63964
- headers: { accept: "application/json" },
63965
- signal: ctl.signal
63966
- }).finally(() => clearTimeout(timer));
63967
- if (!res.ok) return null;
63968
- const { version: latest } = await res.json();
63969
- if (!latest || !olderThan(LOCAL_VERSION, latest)) return null;
63970
- return ` ${import_picocolors8.default.yellow("\u2191")} ${latest} is out, this copy is ${LOCAL_VERSION} \xB7 curl -fsSL ${CREATORS_ORIGIN}/api/cli/install | sh
63971
-
63972
- `;
63973
- } catch {
63974
- return null;
63975
- }
63976
- }
63977
- function makePut(w) {
63978
- return (s) => {
63979
- process.stdout.write(s);
63980
- w?.wrote(s);
63981
- };
63982
- }
63983
- function banner() {
63984
- const w = water();
63985
- if (!w) process.stdout.write("\n" + import_picocolors8.default.cyan(WORDMARK) + "\n\n");
63986
- const put = makePut(w);
63987
- put(` ${import_picocolors8.default.dim(TAGLINE)}
63988
-
63989
- `);
63990
- return { w, put };
63991
- }
63992
- var MENU = {
63993
- compute: { label: "see virtual machine pricing" },
63994
- models: { label: "see inference pricing" },
63995
- phone: { label: "see phone pricing" },
63996
- email: { label: "see email pricing" },
63997
- passwords: { label: "see passwords pricing" },
63998
- docs: { label: "read the docs" },
63999
- poke: { label: "nothing, I'll poke around" },
64000
- wallet: { label: "pair my wallet", hint: "(members only)" }
64001
- };
64002
- var LANES = {
64003
- compute: { key: "compute", name: "virtual machines", docs: "/api/compute/docs" },
64004
- inference: { key: "models", name: "inference", docs: "/api/inference/docs" },
64005
- phone: { key: "phone", name: "phone", docs: "/api/identity/docs/phone" },
64006
- email: { key: "email", name: "email", docs: "/api/identity/docs/email" },
64007
- passwords: { key: "passwords", name: "passwords", docs: "/api/identity/docs/passwords" }
64008
- };
64009
- var LANE_ORDER = ["compute", "inference", "phone", "email", "passwords"];
64010
- function leadLane(lane) {
64011
- return lane === "inference" || lane === "phone" || lane === "email" || lane === "passwords" ? lane : "compute";
64012
- }
64013
- function lanesLedBy(lane) {
64014
- const lead = leadLane(lane);
64015
- return [lead, ...LANE_ORDER.filter((l) => l !== lead)];
64016
- }
64017
- function menuOrder(lane) {
64018
- const browse = lanesLedBy(lane).map((l) => LANES[l].key);
64019
- return [...browse, "docs", "poke", "wallet"];
64020
- }
64021
- function printMenu(put, order, first) {
64022
- put(` ${import_picocolors8.default.bold(first ? "choose how to start:" : "what next:")}
64023
- `);
64024
- order.forEach((k, i) => {
64025
- const item = MENU[k];
64026
- put(` ${import_picocolors8.default.cyan(`${i + 1}.`)} ${item.label}${item.hint ? ` ${import_picocolors8.default.dim(item.hint)}` : ""}
64027
- `);
64028
- });
64029
- }
64030
- async function printDocs(put, lane) {
64031
- const [lead, ...others] = lanesLedBy(lane);
64032
- const url = (l) => `${CREATORS_ORIGIN}${LANES[l].docs}`;
64033
- try {
64034
- const res = await fetch(url(lead), { headers: { accept: "text/markdown, text/plain" } });
64035
- if (!res.ok) throw new Error(String(res.status));
64036
- const md = (await res.text()).replace(/\s+$/, "");
64037
- put(`
64038
- ${import_picocolors8.default.bold(`THE ${LANES[lead].name.toUpperCase()} CONTRACT`)} ${import_picocolors8.default.dim(url(lead))}
64039
-
64040
- `);
64041
- put(md + "\n\n");
64042
- for (const other of others) put(` ${import_picocolors8.default.dim(`the ${LANES[other].name} contract:`)} ${url(other)}
64043
- `);
64044
- put("\n");
64045
- } catch {
64046
- put(` ${import_picocolors8.default.red("\u2715")} could not fetch the contract; the URLs:
64047
- `);
64048
- for (const l of LANE_ORDER) put(` ${import_picocolors8.default.cyan(LANES[l].name.padEnd(16))} ${url(l)}
64049
- `);
64050
- put("\n");
64051
- }
64052
- }
64053
- async function onboard(opts = {}) {
64054
- const profileName = opts.profile ?? DEFAULT_PROFILE;
64055
- const { w, put } = banner();
64056
- const existing = await loadProfile(profileName).catch(() => null);
64057
- if (existing) {
64058
- put(` ${import_picocolors8.default.green("\u2713")} already paired as ${import_picocolors8.default.bold(existing.walletAddress ?? existing.userId)}
64059
-
64060
- `);
64061
- }
64062
- if (!process.stdin.isTTY) {
64063
- put(` No terminal attached, so no menu. The machine door:
64064
-
64065
- `);
64066
- put(` agentgates compute plans --json ${import_picocolors8.default.dim("\xB7 virtual machine pricing, JSON")}
64067
- `);
64068
- put(` agentgates inference models --json ${import_picocolors8.default.dim("\xB7 model pricing, JSON; --tier --tag --org --search filter it")}
64069
- `);
64070
- put(` agentgates phone pricing --json ${import_picocolors8.default.dim("\xB7 number plans, usage and payphone windows, JSON")}
64071
- `);
64072
- put(` agentgates email pricing --json ${import_picocolors8.default.dim("\xB7 the free inbox, plans and per-send price, JSON")}
64073
- `);
64074
- put(` agentgates passwords pricing --json ${import_picocolors8.default.dim("\xB7 plans and per-use meter")}
64075
- `);
64076
- put(` agentgates passwords init ${import_picocolors8.default.dim("\xB7 mint your own key; then add, allow, use, invite. No human needed")}
64077
- `);
64078
- put(` ${CREATORS_ORIGIN}/api/compute/docs ${import_picocolors8.default.dim("\xB7 the buy/read/renew/destroy contract")}
64079
- `);
64080
- put(` ${CREATORS_ORIGIN}/api/inference/docs ${import_picocolors8.default.dim("\xB7 the chat contract, x402 or Bearer")}
64081
- `);
64082
- put(` ${CREATORS_ORIGIN}/api/identity/docs/phone ${import_picocolors8.default.dim("\xB7 the phone contract: numbers, texts, calls, the payphone")}
64083
- `);
64084
- put(` ${CREATORS_ORIGIN}/api/identity/docs/email ${import_picocolors8.default.dim("\xB7 the email contract: inboxes, plans, sends, wait-code")}
64085
- `);
64086
- put(` ${CREATORS_ORIGIN}/api/identity/docs/passwords ${import_picocolors8.default.dim("\xB7 the passwords contract: store, permits, uses")}
64087
- `);
64088
- put(` ${CREATORS_ORIGIN}/llms.txt ${import_picocolors8.default.dim("\xB7 the whole surface")}
64089
-
64090
- `);
64091
- if (!existing) {
64092
- put(` Pairing a wallet needs a human at a browser: ${import_picocolors8.default.bold("agentgates onboard")} in a real terminal.
64093
-
64094
- `);
64095
- }
64096
- const staleNonTty = await staleLine();
64097
- if (staleNonTty) put(staleNonTty);
64098
- return;
64099
- }
64100
- const stale = await staleLine();
64101
- if (stale) put(stale);
64102
- const order = menuOrder(opts.lane).filter((k) => existing ? k !== "wallet" : true);
64103
- printMenu(put, order, true);
64104
- const rl = createInterface({ input: process.stdin, output: process.stdout });
64105
- const exitDefault = String(order.indexOf("poke") + 1);
64106
- let first = true;
64107
- let plain = put;
64108
- try {
64109
- for (; ; ) {
64110
- const fallback = first ? "1" : exitDefault;
64111
- let choice;
64112
- try {
64113
- choice = (await rl.question(` ${import_picocolors8.default.dim(`choice [${fallback}]:`)} `)).trim() || fallback;
64114
- } catch {
64115
- if (first) w?.stop();
64116
- process.stdout.write("\n");
64117
- printNext(makePut(null));
64118
- return;
64119
- }
64120
- if (first) {
64121
- w?.stop();
64122
- plain = makePut(null);
64123
- first = false;
64124
- }
64125
- process.stdout.write("\n");
64126
- const key = order[parseInt(choice, 10) - 1] ?? "poke";
64127
- if (key === "poke") {
64128
- printNext(plain);
64129
- return;
64130
- }
64131
- switch (key) {
64132
- case "wallet":
64133
- try {
64134
- await runLoginFlow({ profile: profileName, jsonMode: false, ttyHeader: "Pairing this terminal with your wallet\u2026" });
64135
- process.stdout.write("\n");
64136
- } catch {
64137
- plain(` ${import_picocolors8.default.red("\u2715")} pairing didn't complete
64138
-
64139
- `);
64140
- }
64141
- break;
64142
- case "compute":
64143
- try {
64144
- await computePlans({});
64145
- } catch {
64146
- plain(` ${import_picocolors8.default.red("\u2715")} could not read the compute catalog
64147
-
64148
- `);
64149
- }
64150
- break;
64151
- case "models":
64152
- try {
64153
- await inferenceModels({});
64154
- } catch {
64155
- plain(` ${import_picocolors8.default.red("\u2715")} could not read the model catalog
64156
-
64157
- `);
64158
- }
64159
- break;
64160
- case "phone":
64161
- try {
64162
- await phonePricing({});
64163
- } catch {
64164
- plain(` ${import_picocolors8.default.red("\u2715")} could not read the phone catalog
64165
-
64166
- `);
64167
- }
64168
- break;
64169
- case "email":
64170
- try {
64171
- await emailPricing({});
64172
- } catch {
64173
- plain(` ${import_picocolors8.default.red("\u2715")} could not read the email catalog
64174
-
64175
- `);
64176
- }
64177
- break;
64178
- case "passwords":
64179
- try {
64180
- await passwordsPricing({});
64181
- } catch {
64182
- plain(` ${import_picocolors8.default.red("\u2715")} could not read the passwords catalog
64183
-
64184
- `);
64185
- }
64186
- break;
64187
- case "docs":
64188
- await printDocs(plain, opts.lane);
64189
- break;
64190
- }
64191
- printMenu(plain, order, false);
64192
- }
64193
- } finally {
64194
- rl.close();
64195
- }
64196
- }
64197
- function printNext(put) {
64198
- put(` ${import_picocolors8.default.dim("agentgates compute plans")} ${import_picocolors8.default.dim("\xB7 virtual machines by the hour")}
64199
- `);
64200
- put(` ${import_picocolors8.default.dim("agentgates inference models")} ${import_picocolors8.default.dim("\xB7 models by the token")}
64201
- `);
64202
- put(` ${import_picocolors8.default.dim("agentgates phone pricing")} ${import_picocolors8.default.dim("\xB7 numbers by the month, calls by the minute")}
64203
- `);
64204
- put(` ${import_picocolors8.default.dim("agentgates email pricing")} ${import_picocolors8.default.dim("\xB7 inboxes free on a balance, sends per message")}
64205
- `);
64206
- put(` ${import_picocolors8.default.dim("agentgates passwords pricing")} ${import_picocolors8.default.dim("\xB7 logins an agent uses and never sees")}
64207
- `);
64208
- put(` ${import_picocolors8.default.dim("agentgates --help")} ${import_picocolors8.default.dim("\xB7 everything else")}
64209
-
64210
- `);
64211
- }
64212
-
64213
64218
  // src/commands/browser.ts
64214
64219
  var import_picocolors9 = __toESM(require_picocolors(), 1);
64215
64220
 
@@ -64254,6 +64259,40 @@ async function readTask(wallet, id2) {
64254
64259
  const answer = await signedFetch(wallet, "GET", `${BROWSER_LANE}/tasks/${encodeURIComponent(id2)}`);
64255
64260
  return expect(answer, "task").task;
64256
64261
  }
64262
+ async function readIdentityBalance(wallet) {
64263
+ const answer = await signedFetch(
64264
+ wallet,
64265
+ "GET",
64266
+ `${LANE}/credits`
64267
+ );
64268
+ const body = expect(answer, "balance");
64269
+ return { balance: body.balance ?? null, entries: body.entries ?? [], rungsUsd: body.rungsUsd ?? [] };
64270
+ }
64271
+ async function readDepositAddress(wallet) {
64272
+ const answer = await signedFetch(wallet, "GET", `${LANE}/deposit`);
64273
+ if (answer.status === 503) {
64274
+ const b2 = answer.body ?? {};
64275
+ return { deposit: null, dark: typeof b2.error === "string" ? b2.error : "deposit addresses are not open yet on this deployment" };
64276
+ }
64277
+ const body = expect(answer, "deposit address");
64278
+ const payToAll = Array.isArray(body.payToAll) ? body.payToAll : [];
64279
+ const chains = payToAll.filter((e) => e && typeof e.chainId === "number" && typeof e.address === "string").map((e) => ({ chainId: e.chainId, network: typeof e.network === "string" ? e.network : String(e.chainId), address: e.address }));
64280
+ if (typeof body.address !== "string" || chains.length === 0) throw new WireError(answer.status, "bad_wire", "the deposit address could not be read", answer.body);
64281
+ return {
64282
+ deposit: {
64283
+ address: body.address,
64284
+ chains,
64285
+ minConfirmations: typeof body.minConfirmations === "number" ? body.minConfirmations : 0,
64286
+ note: typeof body.note === "string" ? body.note : ""
64287
+ },
64288
+ dark: null
64289
+ };
64290
+ }
64291
+ async function scanDeposit(wallet) {
64292
+ const answer = await signedFetch(wallet, "POST", `${LANE}/deposit`, { scan: true });
64293
+ const body = answer.status === 429 ? answer.body ?? {} : expect(answer, "scan");
64294
+ return { scanned: body.scanned === true, credited: typeof body.credited === "number" ? body.credited : 0, balance: body.balance ?? null };
64295
+ }
64257
64296
  async function cancelTask(wallet, id2) {
64258
64297
  const answer = await signedFetch(wallet, "POST", `${BROWSER_LANE}/tasks/${encodeURIComponent(id2)}/cancel`);
64259
64298
  return expect(answer, "cancel").task;
@@ -64269,16 +64308,16 @@ async function waitForTask(wallet, id2, { maxSeconds = 900, everyMs = 5e3, onTic
64269
64308
  }
64270
64309
 
64271
64310
  // src/commands/browser.ts
64272
- var jsonMode2 = (opts) => opts.json === true || !process.stdout.isTTY;
64311
+ var jsonMode3 = (opts) => opts.json === true || !process.stdout.isTTY;
64273
64312
  function emit3(opts, data4, human) {
64274
- if (jsonMode2(opts)) {
64313
+ if (jsonMode3(opts)) {
64275
64314
  process.stdout.write(JSON.stringify(data4, null, 2) + "\n");
64276
64315
  return;
64277
64316
  }
64278
64317
  human();
64279
64318
  }
64280
- function refuse2(opts, error, code, extra = {}) {
64281
- if (jsonMode2(opts)) {
64319
+ function refuse3(opts, error, code, extra = {}) {
64320
+ if (jsonMode3(opts)) {
64282
64321
  process.stdout.write(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
64283
64322
  } else {
64284
64323
  process.stderr.write(` ${error}${code ? import_picocolors9.default.dim(` (${code})`) : ""}
@@ -64287,8 +64326,8 @@ function refuse2(opts, error, code, extra = {}) {
64287
64326
  process.exit(1);
64288
64327
  }
64289
64328
  function failFrom2(opts, err) {
64290
- if (err instanceof WireError) return refuse2(opts, err.message, err.code, { status: err.status });
64291
- return refuse2(opts, err.message ?? String(err), null);
64329
+ if (err instanceof WireError) return refuse3(opts, err.message, err.code, { status: err.status });
64330
+ return refuse3(opts, err.message ?? String(err), null);
64292
64331
  }
64293
64332
  var usd5 = (v) => {
64294
64333
  const n2 = Number(v);
@@ -64386,13 +64425,60 @@ async function browserPricing(opts) {
64386
64425
  failFrom2(opts, err);
64387
64426
  }
64388
64427
  }
64428
+ async function browserBalance(opts) {
64429
+ try {
64430
+ const keys = await requirePasswordsKey();
64431
+ let balance2 = await readIdentityBalance(keys.wallet);
64432
+ const { deposit, dark } = await readDepositAddress(keys.wallet);
64433
+ let scan = null;
64434
+ if (opts.scan && deposit) {
64435
+ const out = await scanDeposit(keys.wallet);
64436
+ scan = { scanned: out.scanned, credited: out.credited };
64437
+ if (out.credited > 0) balance2 = await readIdentityBalance(keys.wallet);
64438
+ }
64439
+ emit3(opts, { ok: true, wallet: keys.wallet.address, balance: balance2.balance, rungsUsd: balance2.rungsUsd, deposit, ...dark ? { depositDark: dark } : {}, ...scan ? { scan } : {} }, () => {
64440
+ process.stdout.write(`
64441
+ ${import_picocolors9.default.bold("BALANCE")} ${import_picocolors9.default.dim(keys.wallet.address)}
64442
+
64443
+ `);
64444
+ if (balance2.balance) {
64445
+ process.stdout.write(` ${import_picocolors9.default.cyan(usd5(balance2.balance.availableUsd))} ${import_picocolors9.default.dim("available")}`);
64446
+ if (Number(balance2.balance.reservedUsd) > 0) process.stdout.write(import_picocolors9.default.dim(` \xB7 ${usd5(balance2.balance.reservedUsd)} reserved by tasks in flight`));
64447
+ process.stdout.write("\n");
64448
+ } else {
64449
+ process.stdout.write(` ${import_picocolors9.default.dim("no balance under this key yet; a top-up opens it")}
64450
+ `);
64451
+ }
64452
+ if (scan) process.stdout.write(` ${import_picocolors9.default.dim(scan.scanned ? `scanned now: ${scan.credited} arrival${scan.credited === 1 ? "" : "s"} credited` : "scanned moments ago; ask again in a few seconds")}
64453
+ `);
64454
+ process.stdout.write("\n");
64455
+ if (deposit) {
64456
+ const names2 = deposit.chains.map((c) => c.network).join(" or ");
64457
+ process.stdout.write(` ${import_picocolors9.default.bold("TOP UP")} ${import_picocolors9.default.dim(`send USDC on ${names2} to your own address`)}
64458
+ `);
64459
+ process.stdout.write(` ${import_picocolors9.default.cyan(deposit.address)}
64460
+ `);
64461
+ process.stdout.write(` ${import_picocolors9.default.dim(`credited after ${deposit.minConfirmations} confirmations; agentgates browser balance --scan credits a fresh arrival now`)}
64462
+ `);
64463
+ } else {
64464
+ process.stdout.write(` ${import_picocolors9.default.dim(dark ?? "deposit addresses are not open yet")}
64465
+ `);
64466
+ if (balance2.rungsUsd.length) process.stdout.write(` ${import_picocolors9.default.dim(`top up over x402: POST /api/identity/credits with {"amountUsd": ${balance2.rungsUsd[0]}} from a wallet that holds USDC`)}
64467
+ `);
64468
+ }
64469
+ process.stdout.write("\n");
64470
+ });
64471
+ } catch (err) {
64472
+ failFrom2(opts, err);
64473
+ }
64474
+ }
64389
64475
  async function browserRun(url, opts) {
64390
64476
  const goal = (opts.task ?? "").trim();
64391
- if (!goal) return refuse2(opts, 'say what the browser agent should do: --task "<words>"', "bad_request");
64477
+ if (!goal) return refuse3(opts, 'say what the browser agent should do: --task "<words>"', "bad_request");
64392
64478
  const maxSteps = opts.steps !== void 0 ? Number(opts.steps) : void 0;
64393
- if (maxSteps !== void 0 && !Number.isInteger(maxSteps)) return refuse2(opts, "--steps must be a whole number", "bad_request");
64479
+ if (maxSteps !== void 0 && !Number.isInteger(maxSteps)) return refuse3(opts, "--steps must be a whole number", "bad_request");
64394
64480
  const maxSeconds = opts.seconds !== void 0 ? Number(opts.seconds) : void 0;
64395
- if (maxSeconds !== void 0 && !Number.isInteger(maxSeconds)) return refuse2(opts, "--seconds must be a whole number", "bad_request");
64481
+ if (maxSeconds !== void 0 && !Number.isInteger(maxSeconds)) return refuse3(opts, "--seconds must be a whole number", "bad_request");
64396
64482
  try {
64397
64483
  const keys = await requirePasswordsKey();
64398
64484
  const task = await postTask(keys.wallet, { url: siteUrl(url), goal, hosts: opts.host, maxSteps, maxSeconds });
@@ -64410,7 +64496,7 @@ async function browserRun(url, opts) {
64410
64496
  const settled = await waitForTask(keys.wallet, task.id, {
64411
64497
  maxSeconds: waitSeconds,
64412
64498
  onTick: (t) => {
64413
- if (jsonMode2(opts) || t.status === lastStatus) return;
64499
+ if (jsonMode3(opts) || t.status === lastStatus) return;
64414
64500
  lastStatus = t.status;
64415
64501
  process.stderr.write(` ${import_picocolors9.default.dim(`${t.status}${t.status === "running" ? ` \xB7 ${t.stepsRun} steps` : ""}`)}
64416
64502
  `);
@@ -64466,7 +64552,7 @@ async function browserTask(id2, opts) {
64466
64552
  const task = opts.wait ? await waitForTask(keys.wallet, id2, {
64467
64553
  maxSeconds: typeof opts.wait === "string" ? Math.max(5, Number(opts.wait) || 0) : 900,
64468
64554
  onTick: (t) => {
64469
- if (!jsonMode2(opts) && !SETTLED.has(t.status)) process.stderr.write(` ${import_picocolors9.default.dim(`${t.status} \xB7 ${t.stepsRun} steps`)}
64555
+ if (!jsonMode3(opts) && !SETTLED.has(t.status)) process.stderr.write(` ${import_picocolors9.default.dim(`${t.status} \xB7 ${t.stepsRun} steps`)}
64470
64556
  `);
64471
64557
  }
64472
64558
  }) : await readTask(keys.wallet, id2);
@@ -64476,17 +64562,340 @@ async function browserTask(id2, opts) {
64476
64562
  }
64477
64563
  }
64478
64564
 
64565
+ // src/commands/onboard.ts
64566
+ var WORDMARK = [
64567
+ " _ _",
64568
+ " __ _ __ _ ___ _ _| |_ __ _ __ _| |_ ___ ___",
64569
+ " / _` / _` / -_) ' \\ _/ _` / _` | _/ -_|_-<",
64570
+ " \\__,_\\__, \\___|_||_\\__\\__, \\__,_|\\__\\___/__/",
64571
+ " |___/ |___/"
64572
+ ].join("\n");
64573
+ var TAGLINE = "Confidential virtual machines, inference, phone numbers and email, paid per use in USDC.";
64574
+ var { version: LOCAL_VERSION } = require_package();
64575
+ function olderThan(a, b2) {
64576
+ const pa = a.split(".").map(Number);
64577
+ const pb = b2.split(".").map(Number);
64578
+ for (let i = 0; i < 3; i++) {
64579
+ if ((pa[i] ?? 0) < (pb[i] ?? 0)) return true;
64580
+ if ((pa[i] ?? 0) > (pb[i] ?? 0)) return false;
64581
+ }
64582
+ return false;
64583
+ }
64584
+ async function staleLine() {
64585
+ try {
64586
+ const ctl = new AbortController();
64587
+ const timer = setTimeout(() => ctl.abort(), 900);
64588
+ const res = await fetch("https://registry.npmjs.org/@agentgates/cli/latest", {
64589
+ headers: { accept: "application/json" },
64590
+ signal: ctl.signal
64591
+ }).finally(() => clearTimeout(timer));
64592
+ if (!res.ok) return null;
64593
+ const { version: latest } = await res.json();
64594
+ if (!latest || !olderThan(LOCAL_VERSION, latest)) return null;
64595
+ return ` ${import_picocolors10.default.yellow("\u2191")} ${latest} is out, this copy is ${LOCAL_VERSION} \xB7 curl -fsSL ${CREATORS_ORIGIN}/api/cli/install | sh
64596
+
64597
+ `;
64598
+ } catch {
64599
+ return null;
64600
+ }
64601
+ }
64602
+ function makePut(w) {
64603
+ return (s) => {
64604
+ process.stdout.write(s);
64605
+ w?.wrote(s);
64606
+ };
64607
+ }
64608
+ function banner() {
64609
+ const w = water();
64610
+ if (!w) process.stdout.write("\n" + import_picocolors10.default.cyan(WORDMARK) + "\n\n");
64611
+ const put = makePut(w);
64612
+ put(` ${import_picocolors10.default.dim(TAGLINE)}
64613
+
64614
+ `);
64615
+ return { w, put };
64616
+ }
64617
+ var MENU = {
64618
+ account: { label: "log in: mint my twelve words, or show my account", hint: "(agentgates init)" },
64619
+ seed: { label: "show my twelve words", hint: "(agentgates init --reveal-seed)" },
64620
+ balance: { label: "my balance and the address that tops it up", hint: "(agentgates browser balance)" },
64621
+ compute: { label: "see virtual machine pricing" },
64622
+ models: { label: "see inference pricing" },
64623
+ phone: { label: "see phone pricing" },
64624
+ email: { label: "see email pricing" },
64625
+ passwords: { label: "see passwords pricing" },
64626
+ docs: { label: "read the docs" },
64627
+ poke: { label: "nothing, I'll poke around" },
64628
+ wallet: { label: "pair my wallet", hint: "(members only)" }
64629
+ };
64630
+ var LANES = {
64631
+ compute: { key: "compute", name: "virtual machines", docs: "/api/compute/docs" },
64632
+ inference: { key: "models", name: "inference", docs: "/api/inference/docs" },
64633
+ phone: { key: "phone", name: "phone", docs: "/api/identity/docs/phone" },
64634
+ email: { key: "email", name: "email", docs: "/api/identity/docs/email" },
64635
+ passwords: { key: "passwords", name: "passwords", docs: "/api/identity/docs/passwords" }
64636
+ };
64637
+ var LANE_ORDER = ["compute", "inference", "phone", "email", "passwords"];
64638
+ function leadLane(lane) {
64639
+ return lane === "inference" || lane === "phone" || lane === "email" || lane === "passwords" ? lane : "compute";
64640
+ }
64641
+ function lanesLedBy(lane) {
64642
+ const lead = leadLane(lane);
64643
+ return [lead, ...LANE_ORDER.filter((l) => l !== lead)];
64644
+ }
64645
+ function menuOrder(lane, hasAccount) {
64646
+ const browse = lanesLedBy(lane).map((l) => LANES[l].key);
64647
+ const account = hasAccount ? ["account", "seed", "balance"] : ["account"];
64648
+ return [...account, ...browse, "docs", "poke", "wallet"];
64649
+ }
64650
+ function printMenu(put, order, first) {
64651
+ put(` ${import_picocolors10.default.bold(first ? "choose how to start:" : "what next:")}
64652
+ `);
64653
+ order.forEach((k, i) => {
64654
+ const item = MENU[k];
64655
+ put(` ${import_picocolors10.default.cyan(`${i + 1}.`)} ${item.label}${item.hint ? ` ${import_picocolors10.default.dim(item.hint)}` : ""}
64656
+ `);
64657
+ });
64658
+ }
64659
+ async function printDocs(put, lane) {
64660
+ const [lead, ...others] = lanesLedBy(lane);
64661
+ const url = (l) => `${CREATORS_ORIGIN}${LANES[l].docs}`;
64662
+ try {
64663
+ const res = await fetch(url(lead), { headers: { accept: "text/markdown, text/plain" } });
64664
+ if (!res.ok) throw new Error(String(res.status));
64665
+ const md = (await res.text()).replace(/\s+$/, "");
64666
+ put(`
64667
+ ${import_picocolors10.default.bold(`THE ${LANES[lead].name.toUpperCase()} CONTRACT`)} ${import_picocolors10.default.dim(url(lead))}
64668
+
64669
+ `);
64670
+ put(md + "\n\n");
64671
+ for (const other of others) put(` ${import_picocolors10.default.dim(`the ${LANES[other].name} contract:`)} ${url(other)}
64672
+ `);
64673
+ put("\n");
64674
+ } catch {
64675
+ put(` ${import_picocolors10.default.red("\u2715")} could not fetch the contract; the URLs:
64676
+ `);
64677
+ for (const l of LANE_ORDER) put(` ${import_picocolors10.default.cyan(LANES[l].name.padEnd(16))} ${url(l)}
64678
+ `);
64679
+ put("\n");
64680
+ }
64681
+ }
64682
+ async function onboard(opts = {}) {
64683
+ const profileName = opts.profile ?? DEFAULT_PROFILE;
64684
+ const { w, put } = banner();
64685
+ const existing = await loadProfile(profileName).catch(() => null);
64686
+ if (existing) {
64687
+ put(` ${import_picocolors10.default.green("\u2713")} already paired as ${import_picocolors10.default.bold(existing.walletAddress ?? existing.userId)}
64688
+ `);
64689
+ }
64690
+ const account = await loadPasswordsKey().catch(() => null);
64691
+ if (account) {
64692
+ put(` ${import_picocolors10.default.green("\u2713")} logged in as ${import_picocolors10.default.bold(account.state.address)} ${import_picocolors10.default.dim(account.state.mnemonic ? "(twelve words on this machine)" : "(a bare key)")}
64693
+
64694
+ `);
64695
+ } else {
64696
+ put(` ${import_picocolors10.default.dim("no account on this machine yet: option 1 mints your twelve words")}
64697
+
64698
+ `);
64699
+ }
64700
+ if (!process.stdin.isTTY) {
64701
+ put(` No terminal attached, so no menu. The machine door:
64702
+
64703
+ `);
64704
+ put(` agentgates compute plans --json ${import_picocolors10.default.dim("\xB7 virtual machine pricing, JSON")}
64705
+ `);
64706
+ put(` agentgates inference models --json ${import_picocolors10.default.dim("\xB7 model pricing, JSON; --tier --tag --org --search filter it")}
64707
+ `);
64708
+ put(` agentgates phone pricing --json ${import_picocolors10.default.dim("\xB7 number plans, usage and payphone windows, JSON")}
64709
+ `);
64710
+ put(` agentgates email pricing --json ${import_picocolors10.default.dim("\xB7 the free inbox, plans and per-send price, JSON")}
64711
+ `);
64712
+ put(` agentgates passwords pricing --json ${import_picocolors10.default.dim("\xB7 plans and per-use meter")}
64713
+ `);
64714
+ put(` agentgates init ${import_picocolors10.default.dim("\xB7 mint your twelve words: your account, printed once with what to tell your human")}
64715
+ `);
64716
+ put(` agentgates init --reveal-seed ${import_picocolors10.default.dim("\xB7 print them again")}
64717
+ `);
64718
+ put(` agentgates browser balance --json ${import_picocolors10.default.dim("\xB7 your balance and the address that tops it up (USDC on Base or Polygon)")}
64719
+ `);
64720
+ put(` agentgates open ${import_picocolors10.default.dim("\xB7 hand this session to a human's browser on this machine")}
64721
+ `);
64722
+ put(` ${CREATORS_ORIGIN}/api/compute/docs ${import_picocolors10.default.dim("\xB7 the buy/read/renew/destroy contract")}
64723
+ `);
64724
+ put(` ${CREATORS_ORIGIN}/api/inference/docs ${import_picocolors10.default.dim("\xB7 the chat contract, x402 or Bearer")}
64725
+ `);
64726
+ put(` ${CREATORS_ORIGIN}/api/identity/docs/phone ${import_picocolors10.default.dim("\xB7 the phone contract: numbers, texts, calls, the payphone")}
64727
+ `);
64728
+ put(` ${CREATORS_ORIGIN}/api/identity/docs/email ${import_picocolors10.default.dim("\xB7 the email contract: inboxes, plans, sends, wait-code")}
64729
+ `);
64730
+ put(` ${CREATORS_ORIGIN}/api/identity/docs/passwords ${import_picocolors10.default.dim("\xB7 the passwords contract: store, permits, uses")}
64731
+ `);
64732
+ put(` ${CREATORS_ORIGIN}/llms.txt ${import_picocolors10.default.dim("\xB7 the whole surface")}
64733
+
64734
+ `);
64735
+ if (!existing) {
64736
+ put(` Pairing a wallet needs a human at a browser: ${import_picocolors10.default.bold("agentgates onboard")} in a real terminal.
64737
+
64738
+ `);
64739
+ }
64740
+ const staleNonTty = await staleLine();
64741
+ if (staleNonTty) put(staleNonTty);
64742
+ return;
64743
+ }
64744
+ const stale = await staleLine();
64745
+ if (stale) put(stale);
64746
+ const order = menuOrder(opts.lane, !!account).filter((k) => existing ? k !== "wallet" : true);
64747
+ printMenu(put, order, true);
64748
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
64749
+ const exitDefault = String(order.indexOf("poke") + 1);
64750
+ let first = true;
64751
+ let plain = put;
64752
+ try {
64753
+ for (; ; ) {
64754
+ const fallback = first ? "1" : exitDefault;
64755
+ let choice;
64756
+ try {
64757
+ choice = (await rl.question(` ${import_picocolors10.default.dim(`choice [${fallback}]:`)} `)).trim() || fallback;
64758
+ } catch {
64759
+ if (first) w?.stop();
64760
+ process.stdout.write("\n");
64761
+ printNext(makePut(null));
64762
+ return;
64763
+ }
64764
+ if (first) {
64765
+ w?.stop();
64766
+ plain = makePut(null);
64767
+ first = false;
64768
+ }
64769
+ process.stdout.write("\n");
64770
+ const key = order[parseInt(choice, 10) - 1] ?? "poke";
64771
+ if (key === "poke") {
64772
+ printNext(plain);
64773
+ return;
64774
+ }
64775
+ switch (key) {
64776
+ case "wallet":
64777
+ try {
64778
+ await runLoginFlow({ profile: profileName, jsonMode: false, ttyHeader: "Pairing this terminal with your wallet\u2026" });
64779
+ process.stdout.write("\n");
64780
+ } catch {
64781
+ plain(` ${import_picocolors10.default.red("\u2715")} pairing didn't complete
64782
+
64783
+ `);
64784
+ }
64785
+ break;
64786
+ case "account":
64787
+ try {
64788
+ await passwordsInit({});
64789
+ } catch {
64790
+ plain(` ${import_picocolors10.default.red("\u2715")} the account could not be read or minted
64791
+
64792
+ `);
64793
+ }
64794
+ break;
64795
+ case "seed":
64796
+ try {
64797
+ await passwordsInit({ revealSeed: true });
64798
+ } catch {
64799
+ plain(` ${import_picocolors10.default.red("\u2715")} the words could not be read
64800
+
64801
+ `);
64802
+ }
64803
+ break;
64804
+ case "balance":
64805
+ try {
64806
+ await browserBalance({});
64807
+ } catch {
64808
+ plain(` ${import_picocolors10.default.red("\u2715")} the balance could not be read
64809
+
64810
+ `);
64811
+ }
64812
+ break;
64813
+ case "compute":
64814
+ try {
64815
+ await computePlans({});
64816
+ } catch {
64817
+ plain(` ${import_picocolors10.default.red("\u2715")} could not read the compute catalog
64818
+
64819
+ `);
64820
+ }
64821
+ break;
64822
+ case "models":
64823
+ try {
64824
+ await inferenceModels({});
64825
+ } catch {
64826
+ plain(` ${import_picocolors10.default.red("\u2715")} could not read the model catalog
64827
+
64828
+ `);
64829
+ }
64830
+ break;
64831
+ case "phone":
64832
+ try {
64833
+ await phonePricing({});
64834
+ } catch {
64835
+ plain(` ${import_picocolors10.default.red("\u2715")} could not read the phone catalog
64836
+
64837
+ `);
64838
+ }
64839
+ break;
64840
+ case "email":
64841
+ try {
64842
+ await emailPricing({});
64843
+ } catch {
64844
+ plain(` ${import_picocolors10.default.red("\u2715")} could not read the email catalog
64845
+
64846
+ `);
64847
+ }
64848
+ break;
64849
+ case "passwords":
64850
+ try {
64851
+ await passwordsPricing({});
64852
+ } catch {
64853
+ plain(` ${import_picocolors10.default.red("\u2715")} could not read the passwords catalog
64854
+
64855
+ `);
64856
+ }
64857
+ break;
64858
+ case "docs":
64859
+ await printDocs(plain, opts.lane);
64860
+ break;
64861
+ }
64862
+ printMenu(plain, order, false);
64863
+ }
64864
+ } finally {
64865
+ rl.close();
64866
+ }
64867
+ }
64868
+ function printNext(put) {
64869
+ put(` ${import_picocolors10.default.dim("agentgates init")} ${import_picocolors10.default.dim("\xB7 your account: mint the twelve words, or show it; --reveal-seed prints the words")}
64870
+ `);
64871
+ put(` ${import_picocolors10.default.dim("agentgates browser balance")} ${import_picocolors10.default.dim("\xB7 your balance and the address that tops it up")}
64872
+ `);
64873
+ put(` ${import_picocolors10.default.dim("agentgates compute plans")} ${import_picocolors10.default.dim("\xB7 virtual machines by the hour")}
64874
+ `);
64875
+ put(` ${import_picocolors10.default.dim("agentgates inference models")} ${import_picocolors10.default.dim("\xB7 models by the token")}
64876
+ `);
64877
+ put(` ${import_picocolors10.default.dim("agentgates phone pricing")} ${import_picocolors10.default.dim("\xB7 numbers by the month, calls by the minute")}
64878
+ `);
64879
+ put(` ${import_picocolors10.default.dim("agentgates email pricing")} ${import_picocolors10.default.dim("\xB7 inboxes free on a balance, sends per message")}
64880
+ `);
64881
+ put(` ${import_picocolors10.default.dim("agentgates passwords pricing")} ${import_picocolors10.default.dim("\xB7 logins an agent uses and never sees")}
64882
+ `);
64883
+ put(` ${import_picocolors10.default.dim("agentgates --help")} ${import_picocolors10.default.dim("\xB7 everything else")}
64884
+
64885
+ `);
64886
+ }
64887
+
64479
64888
  // src/commands/logout.ts
64480
- var import_picocolors10 = __toESM(require_picocolors(), 1);
64889
+ var import_picocolors11 = __toESM(require_picocolors(), 1);
64481
64890
  async function logout(opts) {
64482
64891
  const requested = opts.profile ?? DEFAULT_PROFILE;
64483
64892
  const resolved = await resolveProfile(requested);
64484
64893
  if (!resolved) {
64485
- process.stdout.write(import_picocolors10.default.dim("Not logged in \u2014 nothing to log out.\n"));
64894
+ process.stdout.write(import_picocolors11.default.dim("Not logged in \u2014 nothing to log out.\n"));
64486
64895
  return;
64487
64896
  }
64488
64897
  if (resolved.autoSelected) {
64489
- process.stderr.write(import_picocolors10.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
64898
+ process.stderr.write(import_picocolors11.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
64490
64899
  `));
64491
64900
  }
64492
64901
  const { profile, name: profileName } = resolved;
@@ -64511,15 +64920,15 @@ async function logout(opts) {
64511
64920
  const removed = await deleteProfile(profileName);
64512
64921
  if (removed) {
64513
64922
  process.stdout.write(
64514
- import_picocolors10.default.green(`\u2713 Logged out of profile ${import_picocolors10.default.bold(profileName)}.
64923
+ import_picocolors11.default.green(`\u2713 Logged out of profile ${import_picocolors11.default.bold(profileName)}.
64515
64924
  `)
64516
64925
  );
64517
64926
  }
64518
64927
  if (serverError) {
64519
64928
  process.stderr.write(
64520
- import_picocolors10.default.yellow(
64929
+ import_picocolors11.default.yellow(
64521
64930
  `\u26A0 Couldn't revoke server-side: ${serverError}
64522
- The local bearer is wiped. If the server still has it, revoke from ${import_picocolors10.default.bold("agentgates.ai/settings/pairings")}.
64931
+ The local bearer is wiped. If the server still has it, revoke from ${import_picocolors11.default.bold("agentgates.ai/settings/pairings")}.
64523
64932
  `
64524
64933
  )
64525
64934
  );
@@ -64527,49 +64936,49 @@ async function logout(opts) {
64527
64936
  }
64528
64937
 
64529
64938
  // src/commands/whoami.ts
64530
- var import_picocolors11 = __toESM(require_picocolors(), 1);
64939
+ var import_picocolors12 = __toESM(require_picocolors(), 1);
64531
64940
  async function whoami(opts) {
64532
64941
  const requested = opts.profile ?? DEFAULT_PROFILE;
64533
64942
  const resolved = await resolveProfile(requested);
64534
64943
  if (!resolved) {
64535
- process.stderr.write(import_picocolors11.default.red("Not logged in. Run agentgates login first.\n"));
64944
+ process.stderr.write(import_picocolors12.default.red("Not logged in. Run agentgates login first.\n"));
64536
64945
  process.exit(2);
64537
64946
  }
64538
64947
  if (resolved.autoSelected) {
64539
- process.stderr.write(import_picocolors11.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
64948
+ process.stderr.write(import_picocolors12.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
64540
64949
  `));
64541
64950
  }
64542
64951
  const { profile, name: profileName } = resolved;
64543
- const jsonMode3 = opts.json === true;
64952
+ const jsonMode4 = opts.json === true;
64544
64953
  const outcome = await callWithAutoRelogin({
64545
64954
  profile,
64546
64955
  profileName,
64547
- jsonMode: jsonMode3,
64548
- ttyHeader: import_picocolors11.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
64956
+ jsonMode: jsonMode4,
64957
+ ttyHeader: import_picocolors12.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
64549
64958
  fn: (bearer, origin) => apiFetch("/api/whoami", { bearer, origin })
64550
64959
  });
64551
64960
  if (outcome.kind === "auth_failed") {
64552
- if (jsonMode3) {
64961
+ if (jsonMode4) {
64553
64962
  process.stdout.write(
64554
64963
  JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
64555
64964
  );
64556
64965
  process.exit(1);
64557
64966
  }
64558
- process.stderr.write(import_picocolors11.default.red(`\u2715 ${outcome.reason}.
64967
+ process.stderr.write(import_picocolors12.default.red(`\u2715 ${outcome.reason}.
64559
64968
  `));
64560
64969
  process.exit(1);
64561
64970
  }
64562
64971
  if (outcome.kind === "error") {
64563
64972
  const err = outcome.error;
64564
64973
  if (err instanceof ApiError) {
64565
- process.stderr.write(import_picocolors11.default.red(`\u2715 ${err.message} (HTTP ${err.status})
64974
+ process.stderr.write(import_picocolors12.default.red(`\u2715 ${err.message} (HTTP ${err.status})
64566
64975
  `));
64567
64976
  process.exit(1);
64568
64977
  }
64569
64978
  throw err;
64570
64979
  }
64571
64980
  const me = outcome.result;
64572
- if (jsonMode3) {
64981
+ if (jsonMode4) {
64573
64982
  process.stdout.write(JSON.stringify(me, null, 2) + "\n");
64574
64983
  return;
64575
64984
  }
@@ -64583,7 +64992,7 @@ async function whoami(opts) {
64583
64992
  process.stdout.write(`Solana ${me.solanaAddress}
64584
64993
  `);
64585
64994
  }
64586
- process.stdout.write(`Scopes ${me.scopes.join(", ") || import_picocolors11.default.dim("(none)")}
64995
+ process.stdout.write(`Scopes ${me.scopes.join(", ") || import_picocolors12.default.dim("(none)")}
64587
64996
  `);
64588
64997
  const txCap = me.perTxUSD == null ? "No limit/tx" : `$${me.perTxUSD}/tx`;
64589
64998
  const dayCap = me.perDayUSD == null ? "No limit/day" : `$${me.perDayUSD}/day`;
@@ -64600,7 +65009,7 @@ async function whoami(opts) {
64600
65009
  `
64601
65010
  );
64602
65011
  process.stdout.write(
64603
- `Profile ${profileName === DEFAULT_PROFILE ? import_picocolors11.default.dim("(default)") : profileName}
65012
+ `Profile ${profileName === DEFAULT_PROFILE ? import_picocolors12.default.dim("(default)") : profileName}
64604
65013
  `
64605
65014
  );
64606
65015
  process.stdout.write(AI_DIRECTIVE + "\n");
@@ -64614,7 +65023,7 @@ function formatDate(iso) {
64614
65023
  }
64615
65024
 
64616
65025
  // src/commands/send.ts
64617
- var import_picocolors12 = __toESM(require_picocolors(), 1);
65026
+ var import_picocolors13 = __toESM(require_picocolors(), 1);
64618
65027
 
64619
65028
  // src/lib/status.ts
64620
65029
  var TERMINAL_STATUSES = /* @__PURE__ */ new Set([
@@ -64764,20 +65173,20 @@ async function send(amount, asset, opts) {
64764
65173
  const requested = opts.profile ?? DEFAULT_PROFILE;
64765
65174
  const resolved = await resolveProfile(requested);
64766
65175
  if (!resolved) {
64767
- process.stderr.write(import_picocolors12.default.red("Not logged in. Run agentgates login first.\n"));
65176
+ process.stderr.write(import_picocolors13.default.red("Not logged in. Run agentgates login first.\n"));
64768
65177
  process.exit(2);
64769
65178
  }
64770
65179
  if (resolved.autoSelected) {
64771
- process.stderr.write(import_picocolors12.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
65180
+ process.stderr.write(import_picocolors13.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
64772
65181
  `));
64773
65182
  }
64774
65183
  const { profile, name: profileName } = resolved;
64775
65184
  const stdoutIsTty = process.stdout.isTTY === true;
64776
- const jsonMode3 = opts.json === true || !stdoutIsTty;
65185
+ const jsonMode4 = opts.json === true || !stdoutIsTty;
64777
65186
  const amountNumber = Number(amount);
64778
65187
  if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
64779
65188
  process.stderr.write(
64780
- import_picocolors12.default.red(`\u2715 amount must be a positive number (got ${import_picocolors12.default.bold(amount)}).
65189
+ import_picocolors13.default.red(`\u2715 amount must be a positive number (got ${import_picocolors13.default.bold(amount)}).
64781
65190
  `)
64782
65191
  );
64783
65192
  process.exit(2);
@@ -64785,23 +65194,23 @@ async function send(amount, asset, opts) {
64785
65194
  const assetNormalized = asset.toLowerCase();
64786
65195
  if (assetNormalized !== "native" && assetNormalized !== "usdc") {
64787
65196
  process.stderr.write(
64788
- import_picocolors12.default.red(
64789
- `\u2715 asset must be ${import_picocolors12.default.bold("native")} or ${import_picocolors12.default.bold("usdc")} (got ${import_picocolors12.default.bold(asset)}).
65197
+ import_picocolors13.default.red(
65198
+ `\u2715 asset must be ${import_picocolors13.default.bold("native")} or ${import_picocolors13.default.bold("usdc")} (got ${import_picocolors13.default.bold(asset)}).
64790
65199
  `
64791
65200
  )
64792
65201
  );
64793
65202
  process.exit(2);
64794
65203
  }
64795
65204
  if (!opts.to || opts.to.trim() === "") {
64796
- process.stderr.write(import_picocolors12.default.red(`\u2715 --to <address> is required.
65205
+ process.stderr.write(import_picocolors13.default.red(`\u2715 --to <address> is required.
64797
65206
  `));
64798
65207
  process.exit(2);
64799
65208
  }
64800
65209
  if (isSolanaChainAlias(opts.chain)) {
64801
65210
  if (EVM_ADDRESS_RE.test(opts.to)) {
64802
65211
  process.stderr.write(
64803
- import_picocolors12.default.red(
64804
- `\u2715 --to looks like an EVM address (0x-hex), but --chain is ${import_picocolors12.default.bold("solana")}. Pass a base58 Solana pubkey, or pick an EVM chain.
65212
+ import_picocolors13.default.red(
65213
+ `\u2715 --to looks like an EVM address (0x-hex), but --chain is ${import_picocolors13.default.bold("solana")}. Pass a base58 Solana pubkey, or pick an EVM chain.
64805
65214
  `
64806
65215
  )
64807
65216
  );
@@ -64809,10 +65218,10 @@ async function send(amount, asset, opts) {
64809
65218
  }
64810
65219
  if (!SOLANA_ADDRESS_RE.test(opts.to)) {
64811
65220
  process.stderr.write(
64812
- import_picocolors12.default.red(
64813
- `\u2715 --to must be a base58 Solana pubkey (32\u201344 chars, base58 alphabet) for --chain solana (got ${import_picocolors12.default.bold(opts.to)}).
65221
+ import_picocolors13.default.red(
65222
+ `\u2715 --to must be a base58 Solana pubkey (32\u201344 chars, base58 alphabet) for --chain solana (got ${import_picocolors13.default.bold(opts.to)}).
64814
65223
  `
64815
- ) + import_picocolors12.default.dim(
65224
+ ) + import_picocolors13.default.dim(
64816
65225
  ` SNS resolution is deferred to a future server-side change;
64817
65226
  for now Solana sends require the literal pubkey.
64818
65227
  `
@@ -64823,8 +65232,8 @@ async function send(amount, asset, opts) {
64823
65232
  }
64824
65233
  if (!opts.userStated || opts.userStated.trim() === "") {
64825
65234
  process.stderr.write(
64826
- import_picocolors12.default.red(`\u2715 --user-stated <text> is required.
64827
- `) + import_picocolors12.default.dim(
65235
+ import_picocolors13.default.red(`\u2715 --user-stated <text> is required.
65236
+ `) + import_picocolors13.default.dim(
64828
65237
  ` This is the trust-gap defense: pass the verbatim user request so
64829
65238
  the approval modal can cross-check what the agent thinks the user
64830
65239
  asked for vs. the actual decoded transaction.
@@ -64842,7 +65251,7 @@ async function send(amount, asset, opts) {
64842
65251
  const n2 = Number(opts.maxUsd);
64843
65252
  if (!Number.isFinite(n2) || n2 <= 0) {
64844
65253
  process.stderr.write(
64845
- import_picocolors12.default.red(`\u2715 --max-usd must be a positive number (got ${opts.maxUsd}).
65254
+ import_picocolors13.default.red(`\u2715 --max-usd must be a positive number (got ${opts.maxUsd}).
64846
65255
  `)
64847
65256
  );
64848
65257
  process.exit(2);
@@ -64882,12 +65291,12 @@ async function send(amount, asset, opts) {
64882
65291
  try {
64883
65292
  activeProfile = await runLoginFlow({
64884
65293
  profile: profileName,
64885
- jsonMode: jsonMode3,
65294
+ jsonMode: jsonMode4,
64886
65295
  origin: activeProfile.mcpOrigin,
64887
- ttyHeader: import_picocolors12.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026")
65296
+ ttyHeader: import_picocolors13.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026")
64888
65297
  });
64889
65298
  } catch (reloginErr) {
64890
- if (jsonMode3) {
65299
+ if (jsonMode4) {
64891
65300
  emitNdjson({
64892
65301
  ok: false,
64893
65302
  status: "auth_failed",
@@ -64896,7 +65305,7 @@ async function send(amount, asset, opts) {
64896
65305
  process.exit(1);
64897
65306
  }
64898
65307
  process.stderr.write(
64899
- import_picocolors12.default.red(`\u2715 Auto-relogin failed: ${reloginErr.message}
65308
+ import_picocolors13.default.red(`\u2715 Auto-relogin failed: ${reloginErr.message}
64900
65309
  `)
64901
65310
  );
64902
65311
  process.exit(1);
@@ -64910,7 +65319,7 @@ async function send(amount, asset, opts) {
64910
65319
  });
64911
65320
  } catch (retryErr) {
64912
65321
  if (retryErr instanceof ApiError) {
64913
- if (jsonMode3) {
65322
+ if (jsonMode4) {
64914
65323
  emitNdjson({
64915
65324
  ok: false,
64916
65325
  status: retryErr.status === 401 ? "auth_failed" : "propose_failed",
@@ -64920,7 +65329,7 @@ async function send(amount, asset, opts) {
64920
65329
  process.exit(1);
64921
65330
  }
64922
65331
  process.stderr.write(
64923
- import_picocolors12.default.red(`\u2715 ${retryErr.message} (HTTP ${retryErr.status})
65332
+ import_picocolors13.default.red(`\u2715 ${retryErr.message} (HTTP ${retryErr.status})
64924
65333
  `)
64925
65334
  );
64926
65335
  process.exit(1);
@@ -64928,7 +65337,7 @@ async function send(amount, asset, opts) {
64928
65337
  throw retryErr;
64929
65338
  }
64930
65339
  } else if (err instanceof ApiError) {
64931
- if (jsonMode3) {
65340
+ if (jsonMode4) {
64932
65341
  emitNdjson({
64933
65342
  ok: false,
64934
65343
  status: "propose_failed",
@@ -64937,7 +65346,7 @@ async function send(amount, asset, opts) {
64937
65346
  });
64938
65347
  process.exit(1);
64939
65348
  }
64940
- process.stderr.write(import_picocolors12.default.red(`\u2715 ${err.message} (HTTP ${err.status})
65349
+ process.stderr.write(import_picocolors13.default.red(`\u2715 ${err.message} (HTTP ${err.status})
64941
65350
  `));
64942
65351
  process.exit(1);
64943
65352
  } else {
@@ -64945,7 +65354,7 @@ async function send(amount, asset, opts) {
64945
65354
  }
64946
65355
  }
64947
65356
  if (isBlocked(proposed)) {
64948
- if (jsonMode3) {
65357
+ if (jsonMode4) {
64949
65358
  const envelope = {
64950
65359
  ok: false,
64951
65360
  status: "blocked",
@@ -64963,17 +65372,17 @@ async function send(amount, asset, opts) {
64963
65372
  if (proposed.detail) {
64964
65373
  const d = proposed.detail;
64965
65374
  process.stderr.write(
64966
- import_picocolors12.default.red(`\u2715 ${d.asset_symbol ?? "Asset"} on ${d.chain_name ?? "chain"}: `) + `have ${d.balance}, need ${d.required} (short ${d.deficit})
65375
+ import_picocolors13.default.red(`\u2715 ${d.asset_symbol ?? "Asset"} on ${d.chain_name ?? "chain"}: `) + `have ${d.balance}, need ${d.required} (short ${d.deficit})
64967
65376
  `
64968
65377
  );
64969
65378
  } else {
64970
- process.stderr.write(import_picocolors12.default.red(`\u2715 ${proposed.reason}
65379
+ process.stderr.write(import_picocolors13.default.red(`\u2715 ${proposed.reason}
64971
65380
  `));
64972
65381
  }
64973
65382
  if (proposed.upgrade_url) {
64974
65383
  process.stderr.write(
64975
65384
  ` Open this to grant access, then re-run the command:
64976
- ${import_picocolors12.default.cyan(proposed.upgrade_url)}
65385
+ ${import_picocolors13.default.cyan(proposed.upgrade_url)}
64977
65386
  `
64978
65387
  );
64979
65388
  }
@@ -64983,21 +65392,21 @@ async function send(amount, asset, opts) {
64983
65392
  const a = proposed.recommended_actions[i];
64984
65393
  process.stderr.write(` ${i + 1}. ${a.label}
64985
65394
  `);
64986
- if (a.reasoning) process.stderr.write(import_picocolors12.default.dim(` ${a.reasoning}
65395
+ if (a.reasoning) process.stderr.write(import_picocolors13.default.dim(` ${a.reasoning}
64987
65396
  `));
64988
65397
  if (a.action_intent && a.action_intent.external_url) {
64989
65398
  process.stderr.write(
64990
- ` ${import_picocolors12.default.cyan(a.action_intent.external_url)}
65399
+ ` ${import_picocolors13.default.cyan(a.action_intent.external_url)}
64991
65400
  `
64992
65401
  );
64993
65402
  }
64994
65403
  }
64995
65404
  }
64996
65405
  if (proposed.suggestions && proposed.suggestions.length > 0) {
64997
- process.stderr.write(import_picocolors12.default.dim("\n Other ways to fund:\n"));
65406
+ process.stderr.write(import_picocolors13.default.dim("\n Other ways to fund:\n"));
64998
65407
  for (const s of proposed.suggestions) {
64999
65408
  if (s.kind === "ask_user") continue;
65000
- process.stderr.write(import_picocolors12.default.dim(` \u2022 ${s.label}
65409
+ process.stderr.write(import_picocolors13.default.dim(` \u2022 ${s.label}
65001
65410
  `));
65002
65411
  }
65003
65412
  }
@@ -65009,7 +65418,7 @@ async function send(amount, asset, opts) {
65009
65418
  if (process.env.CI === "1" || process.env.CI === "true") return false;
65010
65419
  return true;
65011
65420
  })();
65012
- if (jsonMode3) {
65421
+ if (jsonMode4) {
65013
65422
  emitNdjson({
65014
65423
  ok: true,
65015
65424
  status: "proposed",
@@ -65024,8 +65433,8 @@ async function send(amount, asset, opts) {
65024
65433
  } else {
65025
65434
  process.stdout.write(
65026
65435
  `
65027
- ${import_picocolors12.default.bold("Proposed.")} Open this URL to approve with biometric:
65028
- ${import_picocolors12.default.cyan(proposed.approval_url)}
65436
+ ${import_picocolors13.default.bold("Proposed.")} Open this URL to approve with biometric:
65437
+ ${import_picocolors13.default.cyan(proposed.approval_url)}
65029
65438
 
65030
65439
  `
65031
65440
  );
@@ -65041,10 +65450,10 @@ ${import_picocolors12.default.bold("Proposed.")} Open this URL to approve with b
65041
65450
  intervalMs: POLL_INTERVAL_MS,
65042
65451
  giveUpMs: POLL_GIVEUP_MS,
65043
65452
  onTick: (s) => {
65044
- if (jsonMode3) {
65453
+ if (jsonMode4) {
65045
65454
  emitNdjson({ status: s.status, intent_id: s.approval_id });
65046
65455
  } else {
65047
- process.stdout.write(` ${describeStatus(s.status)}${import_picocolors12.default.dim("\u2026")}\r`);
65456
+ process.stdout.write(` ${describeStatus(s.status)}${import_picocolors13.default.dim("\u2026")}\r`);
65048
65457
  }
65049
65458
  }
65050
65459
  });
@@ -65056,12 +65465,12 @@ ${import_picocolors12.default.bold("Proposed.")} Open this URL to approve with b
65056
65465
  try {
65057
65466
  activeProfile = await runLoginFlow({
65058
65467
  profile: profileName,
65059
- jsonMode: jsonMode3,
65468
+ jsonMode: jsonMode4,
65060
65469
  origin: activeProfile.mcpOrigin,
65061
- ttyHeader: import_picocolors12.default.dim("Bearer expired mid-poll \u2014 re-pairing this terminal\u2026")
65470
+ ttyHeader: import_picocolors13.default.dim("Bearer expired mid-poll \u2014 re-pairing this terminal\u2026")
65062
65471
  });
65063
65472
  } catch (reloginErr) {
65064
- if (jsonMode3) {
65473
+ if (jsonMode4) {
65065
65474
  emitNdjson({
65066
65475
  ok: false,
65067
65476
  status: "auth_failed",
@@ -65071,7 +65480,7 @@ ${import_picocolors12.default.bold("Proposed.")} Open this URL to approve with b
65071
65480
  process.exit(1);
65072
65481
  }
65073
65482
  process.stderr.write(
65074
- "\n" + import_picocolors12.default.red(`\u2715 Auto-relogin failed: ${reloginErr.message}
65483
+ "\n" + import_picocolors13.default.red(`\u2715 Auto-relogin failed: ${reloginErr.message}
65075
65484
  `)
65076
65485
  );
65077
65486
  process.exit(1);
@@ -65079,7 +65488,7 @@ ${import_picocolors12.default.bold("Proposed.")} Open this URL to approve with b
65079
65488
  try {
65080
65489
  final = await runPoll(activeProfile);
65081
65490
  } catch (retryErr) {
65082
- if (jsonMode3) {
65491
+ if (jsonMode4) {
65083
65492
  emitNdjson({
65084
65493
  ok: false,
65085
65494
  status: retryErr instanceof ApiError && retryErr.status === 401 ? "auth_failed" : "poll_failed",
@@ -65089,13 +65498,13 @@ ${import_picocolors12.default.bold("Proposed.")} Open this URL to approve with b
65089
65498
  process.exit(1);
65090
65499
  }
65091
65500
  process.stderr.write(
65092
- "\n" + import_picocolors12.default.red(`\u2715 Status poll failed: ${retryErr.message}
65501
+ "\n" + import_picocolors13.default.red(`\u2715 Status poll failed: ${retryErr.message}
65093
65502
  `)
65094
65503
  );
65095
65504
  process.exit(1);
65096
65505
  }
65097
65506
  } else {
65098
- if (jsonMode3) {
65507
+ if (jsonMode4) {
65099
65508
  emitNdjson({
65100
65509
  ok: false,
65101
65510
  status: "poll_failed",
@@ -65105,14 +65514,14 @@ ${import_picocolors12.default.bold("Proposed.")} Open this URL to approve with b
65105
65514
  process.exit(1);
65106
65515
  }
65107
65516
  process.stderr.write(
65108
- "\n" + import_picocolors12.default.red(`\u2715 Status poll failed: ${err.message}
65517
+ "\n" + import_picocolors13.default.red(`\u2715 Status poll failed: ${err.message}
65109
65518
  `)
65110
65519
  );
65111
65520
  process.exit(1);
65112
65521
  }
65113
65522
  }
65114
65523
  const explorer = final.tx_hash != null ? explorerUrl(final.chain_id, final.tx_hash) : null;
65115
- if (jsonMode3) {
65524
+ if (jsonMode4) {
65116
65525
  emitNdjson({
65117
65526
  ok: final.status === "mined",
65118
65527
  status: final.status,
@@ -65125,19 +65534,19 @@ ${import_picocolors12.default.bold("Proposed.")} Open this URL to approve with b
65125
65534
  }
65126
65535
  process.stdout.write("\n");
65127
65536
  if (final.status === "mined") {
65128
- process.stdout.write(import_picocolors12.default.green("\u2713 Mined.") + "\n");
65537
+ process.stdout.write(import_picocolors13.default.green("\u2713 Mined.") + "\n");
65129
65538
  if (final.tx_hash) {
65130
65539
  process.stdout.write(` Tx ${final.tx_hash}
65131
65540
  `);
65132
65541
  }
65133
65542
  if (explorer) {
65134
- process.stdout.write(` Explorer ${import_picocolors12.default.cyan(explorer)}
65543
+ process.stdout.write(` Explorer ${import_picocolors13.default.cyan(explorer)}
65135
65544
  `);
65136
65545
  }
65137
65546
  process.exit(0);
65138
65547
  }
65139
65548
  const label = final.status === "rejected" ? "Rejected by user" : final.status === "expired" ? "Expired (TTL elapsed before approval)" : final.status === "failed" ? "Broadcast failed" : `Ended in unexpected status: ${final.status}`;
65140
- process.stderr.write(import_picocolors12.default.red(`\u2715 ${label}.
65549
+ process.stderr.write(import_picocolors13.default.red(`\u2715 ${label}.
65141
65550
  `));
65142
65551
  process.exit(1);
65143
65552
  }
@@ -65165,7 +65574,7 @@ function describeStatus(s) {
65165
65574
  }
65166
65575
 
65167
65576
  // src/commands/status.ts
65168
- var import_picocolors13 = __toESM(require_picocolors(), 1);
65577
+ var import_picocolors14 = __toESM(require_picocolors(), 1);
65169
65578
  var WATCH_GIVEUP_MS = 10 * 6e4;
65170
65579
  function explorerUrl2(chainId, hash2) {
65171
65580
  switch (chainId) {
@@ -65183,36 +65592,36 @@ function explorerUrl2(chainId, hash2) {
65183
65592
  }
65184
65593
  async function status2(intentId, opts) {
65185
65594
  if (!intentId || intentId.trim() === "") {
65186
- process.stderr.write(import_picocolors13.default.red("\u2715 Missing intent id.\n"));
65595
+ process.stderr.write(import_picocolors14.default.red("\u2715 Missing intent id.\n"));
65187
65596
  process.exit(2);
65188
65597
  }
65189
65598
  const requested = opts.profile ?? DEFAULT_PROFILE;
65190
65599
  const resolved = await resolveProfile(requested);
65191
65600
  if (!resolved) {
65192
- process.stderr.write(import_picocolors13.default.red("Not logged in. Run agentgates login first.\n"));
65601
+ process.stderr.write(import_picocolors14.default.red("Not logged in. Run agentgates login first.\n"));
65193
65602
  process.exit(2);
65194
65603
  }
65195
65604
  if (resolved.autoSelected) {
65196
- process.stderr.write(import_picocolors13.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
65605
+ process.stderr.write(import_picocolors14.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
65197
65606
  `));
65198
65607
  }
65199
65608
  const { profile, name: profileName } = resolved;
65200
- const jsonMode3 = opts.json === true;
65609
+ const jsonMode4 = opts.json === true;
65201
65610
  const outcome = await callWithAutoRelogin({
65202
65611
  profile,
65203
65612
  profileName,
65204
- jsonMode: jsonMode3,
65205
- ttyHeader: import_picocolors13.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
65613
+ jsonMode: jsonMode4,
65614
+ ttyHeader: import_picocolors14.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
65206
65615
  fn: (bearer, origin) => fetchStatus({ intentId, bearer, origin })
65207
65616
  });
65208
65617
  if (outcome.kind === "auth_failed") {
65209
- if (jsonMode3) {
65618
+ if (jsonMode4) {
65210
65619
  process.stdout.write(
65211
65620
  JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
65212
65621
  );
65213
65622
  process.exit(1);
65214
65623
  }
65215
- process.stderr.write(import_picocolors13.default.red(`\u2715 ${outcome.reason}.
65624
+ process.stderr.write(import_picocolors14.default.red(`\u2715 ${outcome.reason}.
65216
65625
  `));
65217
65626
  process.exit(1);
65218
65627
  }
@@ -65220,11 +65629,11 @@ async function status2(intentId, opts) {
65220
65629
  const err = outcome.error;
65221
65630
  if (err instanceof ApiError) {
65222
65631
  if (err.status === 404) {
65223
- process.stderr.write(import_picocolors13.default.red(`\u2715 No intent with id ${intentId}.
65632
+ process.stderr.write(import_picocolors14.default.red(`\u2715 No intent with id ${intentId}.
65224
65633
  `));
65225
65634
  process.exit(1);
65226
65635
  }
65227
- process.stderr.write(import_picocolors13.default.red(`\u2715 ${err.message} (HTTP ${err.status})
65636
+ process.stderr.write(import_picocolors14.default.red(`\u2715 ${err.message} (HTTP ${err.status})
65228
65637
  `));
65229
65638
  process.exit(1);
65230
65639
  }
@@ -65233,9 +65642,9 @@ async function status2(intentId, opts) {
65233
65642
  let snap = outcome.result;
65234
65643
  let activeProfile = outcome.profile;
65235
65644
  if (opts.watch && !isTerminalStatus(snap.status)) {
65236
- if (!jsonMode3) {
65645
+ if (!jsonMode4) {
65237
65646
  printSnap(snap);
65238
- process.stdout.write(import_picocolors13.default.dim("Watching\u2026\n"));
65647
+ process.stdout.write(import_picocolors14.default.dim("Watching\u2026\n"));
65239
65648
  }
65240
65649
  const runWatchPoll = (p) => streamStatusUntilTerminal({
65241
65650
  intentId,
@@ -65245,8 +65654,8 @@ async function status2(intentId, opts) {
65245
65654
  intervalMs: 0,
65246
65655
  giveUpMs: WATCH_GIVEUP_MS,
65247
65656
  onTick: (s) => {
65248
- if (!jsonMode3) {
65249
- process.stdout.write(` ${import_picocolors13.default.dim("\u2192")} ${s.status}
65657
+ if (!jsonMode4) {
65658
+ process.stdout.write(` ${import_picocolors14.default.dim("\u2192")} ${s.status}
65250
65659
  `);
65251
65660
  }
65252
65661
  }
@@ -65259,12 +65668,12 @@ async function status2(intentId, opts) {
65259
65668
  try {
65260
65669
  activeProfile = await runLoginFlow({
65261
65670
  profile: profileName,
65262
- jsonMode: jsonMode3,
65671
+ jsonMode: jsonMode4,
65263
65672
  origin: activeProfile.mcpOrigin,
65264
- ttyHeader: import_picocolors13.default.dim("Bearer expired mid-watch \u2014 re-pairing\u2026")
65673
+ ttyHeader: import_picocolors14.default.dim("Bearer expired mid-watch \u2014 re-pairing\u2026")
65265
65674
  });
65266
65675
  } catch (reloginErr) {
65267
- if (jsonMode3) {
65676
+ if (jsonMode4) {
65268
65677
  process.stdout.write(
65269
65678
  JSON.stringify({
65270
65679
  ok: false,
@@ -65275,7 +65684,7 @@ async function status2(intentId, opts) {
65275
65684
  process.exit(1);
65276
65685
  }
65277
65686
  process.stderr.write(
65278
- import_picocolors13.default.red(`\u2715 Auto-relogin failed: ${reloginErr.message}
65687
+ import_picocolors14.default.red(`\u2715 Auto-relogin failed: ${reloginErr.message}
65279
65688
  `)
65280
65689
  );
65281
65690
  process.exit(1);
@@ -65283,24 +65692,24 @@ async function status2(intentId, opts) {
65283
65692
  try {
65284
65693
  final = await runWatchPoll(activeProfile);
65285
65694
  } catch (retryErr) {
65286
- process.stderr.write(import_picocolors13.default.red(`\u2715 ${retryErr.message}
65695
+ process.stderr.write(import_picocolors14.default.red(`\u2715 ${retryErr.message}
65287
65696
  `));
65288
65697
  process.exit(1);
65289
65698
  }
65290
65699
  } else {
65291
- process.stderr.write(import_picocolors13.default.red(`\u2715 ${err.message}
65700
+ process.stderr.write(import_picocolors14.default.red(`\u2715 ${err.message}
65292
65701
  `));
65293
65702
  process.exit(1);
65294
65703
  }
65295
65704
  }
65296
- if (jsonMode3) {
65705
+ if (jsonMode4) {
65297
65706
  process.stdout.write(JSON.stringify(final, null, 2) + "\n");
65298
65707
  } else {
65299
65708
  printSnap(final);
65300
65709
  }
65301
65710
  process.exit(final.status === "mined" ? 0 : 1);
65302
65711
  }
65303
- if (jsonMode3) {
65712
+ if (jsonMode4) {
65304
65713
  process.stdout.write(JSON.stringify(snap, null, 2) + "\n");
65305
65714
  process.exit(snap.status === "mined" ? 0 : 0);
65306
65715
  }
@@ -65309,7 +65718,7 @@ async function status2(intentId, opts) {
65309
65718
  }
65310
65719
  function printSnap(s) {
65311
65720
  const explorer = s.tx_hash ? explorerUrl2(s.chain_id, s.tx_hash) : null;
65312
- const colorFn = s.status === "mined" ? import_picocolors13.default.green : s.status === "rejected" || s.status === "expired" || s.status === "failed" ? import_picocolors13.default.red : import_picocolors13.default.cyan;
65721
+ const colorFn = s.status === "mined" ? import_picocolors14.default.green : s.status === "rejected" || s.status === "expired" || s.status === "failed" ? import_picocolors14.default.red : import_picocolors14.default.cyan;
65313
65722
  process.stdout.write(`Intent ${s.approval_id}
65314
65723
  `);
65315
65724
  process.stdout.write(`Status ${colorFn(s.status)}
@@ -65324,12 +65733,12 @@ function printSnap(s) {
65324
65733
  process.stdout.write(`Tx ${s.tx_hash}
65325
65734
  `);
65326
65735
  if (explorer) {
65327
- process.stdout.write(`Explorer ${import_picocolors13.default.cyan(explorer)}
65736
+ process.stdout.write(`Explorer ${import_picocolors14.default.cyan(explorer)}
65328
65737
  `);
65329
65738
  }
65330
65739
  }
65331
65740
  if (!isTerminalStatus(s.status)) {
65332
- process.stdout.write(`Approve ${import_picocolors13.default.cyan(s.approval_url)}
65741
+ process.stdout.write(`Approve ${import_picocolors14.default.cyan(s.approval_url)}
65333
65742
  `);
65334
65743
  }
65335
65744
  process.stdout.write(`Created ${formatDate2(s.created_at)}
@@ -65346,7 +65755,7 @@ function formatDate2(iso) {
65346
65755
  }
65347
65756
 
65348
65757
  // src/commands/balance.ts
65349
- var import_picocolors14 = __toESM(require_picocolors(), 1);
65758
+ var import_picocolors15 = __toESM(require_picocolors(), 1);
65350
65759
  var CHAIN_ALIASES = {
65351
65760
  "1": 1,
65352
65761
  ethereum: 1,
@@ -65369,11 +65778,11 @@ async function balance(opts) {
65369
65778
  const requested = opts.profile ?? DEFAULT_PROFILE;
65370
65779
  const resolved = await resolveProfile(requested);
65371
65780
  if (!resolved) {
65372
- process.stderr.write(import_picocolors14.default.red("Not logged in. Run agentgates login first.\n"));
65781
+ process.stderr.write(import_picocolors15.default.red("Not logged in. Run agentgates login first.\n"));
65373
65782
  process.exit(2);
65374
65783
  }
65375
65784
  if (resolved.autoSelected) {
65376
- process.stderr.write(import_picocolors14.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
65785
+ process.stderr.write(import_picocolors15.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
65377
65786
  `));
65378
65787
  }
65379
65788
  const { profile, name: profileName } = resolved;
@@ -65383,8 +65792,8 @@ async function balance(opts) {
65383
65792
  const id2 = CHAIN_ALIASES[key];
65384
65793
  if (id2 === void 0) {
65385
65794
  process.stderr.write(
65386
- import_picocolors14.default.red(
65387
- `\u2715 Unknown chain ${import_picocolors14.default.bold(opts.chain)}. Supported: ${import_picocolors14.default.bold("1/ethereum")}, ${import_picocolors14.default.bold("137/polygon")}, ${import_picocolors14.default.bold("8453/base")}, ${import_picocolors14.default.bold("42161/arbitrum")}, ${import_picocolors14.default.bold("900/solana")}.
65795
+ import_picocolors15.default.red(
65796
+ `\u2715 Unknown chain ${import_picocolors15.default.bold(opts.chain)}. Supported: ${import_picocolors15.default.bold("1/ethereum")}, ${import_picocolors15.default.bold("137/polygon")}, ${import_picocolors15.default.bold("8453/base")}, ${import_picocolors15.default.bold("42161/arbitrum")}, ${import_picocolors15.default.bold("900/solana")}.
65388
65797
  `
65389
65798
  )
65390
65799
  );
@@ -65392,29 +65801,29 @@ async function balance(opts) {
65392
65801
  }
65393
65802
  chainFilter = id2;
65394
65803
  }
65395
- const jsonMode3 = opts.json === true;
65804
+ const jsonMode4 = opts.json === true;
65396
65805
  const outcome = await callWithAutoRelogin({
65397
65806
  profile,
65398
65807
  profileName,
65399
- jsonMode: jsonMode3,
65400
- ttyHeader: import_picocolors14.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
65808
+ jsonMode: jsonMode4,
65809
+ ttyHeader: import_picocolors15.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
65401
65810
  fn: (bearer, origin) => apiFetch("/api/balances", { bearer, origin })
65402
65811
  });
65403
65812
  if (outcome.kind === "auth_failed") {
65404
- if (jsonMode3) {
65813
+ if (jsonMode4) {
65405
65814
  process.stdout.write(
65406
65815
  JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
65407
65816
  );
65408
65817
  process.exit(1);
65409
65818
  }
65410
- process.stderr.write(import_picocolors14.default.red(`\u2715 ${outcome.reason}.
65819
+ process.stderr.write(import_picocolors15.default.red(`\u2715 ${outcome.reason}.
65411
65820
  `));
65412
65821
  process.exit(1);
65413
65822
  }
65414
65823
  if (outcome.kind === "error") {
65415
65824
  const err = outcome.error;
65416
65825
  if (err instanceof ApiError) {
65417
- process.stderr.write(import_picocolors14.default.red(`\u2715 ${err.message} (HTTP ${err.status})
65826
+ process.stderr.write(import_picocolors15.default.red(`\u2715 ${err.message} (HTTP ${err.status})
65418
65827
  `));
65419
65828
  process.exit(1);
65420
65829
  }
@@ -65422,7 +65831,7 @@ async function balance(opts) {
65422
65831
  }
65423
65832
  const res = outcome.result;
65424
65833
  const filtered = chainFilter !== null ? res.chains.filter((c) => c.chainId === chainFilter) : res.chains;
65425
- if (jsonMode3) {
65834
+ if (jsonMode4) {
65426
65835
  process.stdout.write(
65427
65836
  JSON.stringify(
65428
65837
  chainFilter !== null ? { ...res, chains: filtered } : res,
@@ -65444,7 +65853,7 @@ async function balance(opts) {
65444
65853
  }
65445
65854
  if (filtered.length === 0) {
65446
65855
  process.stdout.write(
65447
- import_picocolors14.default.dim(
65856
+ import_picocolors15.default.dim(
65448
65857
  chainFilter !== null ? `No balances on chain ${chainFilter}.
65449
65858
  ` : `No chain balances returned.
65450
65859
  `
@@ -65456,7 +65865,7 @@ async function balance(opts) {
65456
65865
  const errorLines = [];
65457
65866
  for (const c of filtered) {
65458
65867
  if (c.error) {
65459
- errorLines.push(`${c.chainName} ${import_picocolors14.default.red(`(read failed: ${c.error})`)}`);
65868
+ errorLines.push(`${c.chainName} ${import_picocolors15.default.red(`(read failed: ${c.error})`)}`);
65460
65869
  continue;
65461
65870
  }
65462
65871
  if (c.native.balance > 0) {
@@ -65477,7 +65886,7 @@ async function balance(opts) {
65477
65886
  }
65478
65887
  }
65479
65888
  if (rows.length === 0 && errorLines.length === 0) {
65480
- process.stdout.write(import_picocolors14.default.dim(`All balances are zero.
65889
+ process.stdout.write(import_picocolors15.default.dim(`All balances are zero.
65481
65890
  `));
65482
65891
  process.stdout.write(AI_DIRECTIVE + "\n");
65483
65892
  return;
@@ -65487,7 +65896,7 @@ async function balance(opts) {
65487
65896
  const colAsset = Math.max(5, ...rows.map((r) => r.asset.length));
65488
65897
  const colBalance = Math.max(7, ...rows.map((r) => r.balance.length));
65489
65898
  const header = "Chain".padEnd(colChain) + " " + "Asset".padEnd(colAsset) + " " + "Balance".padStart(colBalance);
65490
- process.stdout.write(import_picocolors14.default.dim(header) + "\n");
65899
+ process.stdout.write(import_picocolors15.default.dim(header) + "\n");
65491
65900
  for (const r of rows) {
65492
65901
  process.stdout.write(
65493
65902
  r.chain.padEnd(colChain) + " " + r.asset.padEnd(colAsset) + " " + r.balance.padStart(colBalance) + "\n"
@@ -65500,7 +65909,7 @@ async function balance(opts) {
65500
65909
  `);
65501
65910
  }
65502
65911
  if (res.fetched_at) {
65503
- process.stdout.write("\n" + import_picocolors14.default.dim(`Fetched ${res.fetched_at}
65912
+ process.stdout.write("\n" + import_picocolors15.default.dim(`Fetched ${res.fetched_at}
65504
65913
  `));
65505
65914
  }
65506
65915
  process.stdout.write(AI_DIRECTIVE + "\n");
@@ -65513,18 +65922,18 @@ function formatBalance(value, decimals) {
65513
65922
  }
65514
65923
 
65515
65924
  // src/commands/history.ts
65516
- var import_picocolors15 = __toESM(require_picocolors(), 1);
65925
+ var import_picocolors16 = __toESM(require_picocolors(), 1);
65517
65926
  var DEFAULT_LIMIT = 20;
65518
65927
  var SERVER_MAX_LIMIT = 100;
65519
65928
  async function history(opts) {
65520
65929
  const requested = opts.profile ?? DEFAULT_PROFILE;
65521
65930
  const resolved = await resolveProfile(requested);
65522
65931
  if (!resolved) {
65523
- process.stderr.write(import_picocolors15.default.red("Not logged in. Run agentgates login first.\n"));
65932
+ process.stderr.write(import_picocolors16.default.red("Not logged in. Run agentgates login first.\n"));
65524
65933
  process.exit(2);
65525
65934
  }
65526
65935
  if (resolved.autoSelected) {
65527
- process.stderr.write(import_picocolors15.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
65936
+ process.stderr.write(import_picocolors16.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
65528
65937
  `));
65529
65938
  }
65530
65939
  const { profile, name: profileName } = resolved;
@@ -65533,14 +65942,14 @@ async function history(opts) {
65533
65942
  const n2 = Number(opts.limit);
65534
65943
  if (!Number.isFinite(n2) || n2 <= 0 || !Number.isInteger(n2)) {
65535
65944
  process.stderr.write(
65536
- import_picocolors15.default.red(`\u2715 --limit must be a positive integer (got ${import_picocolors15.default.bold(opts.limit)}).
65945
+ import_picocolors16.default.red(`\u2715 --limit must be a positive integer (got ${import_picocolors16.default.bold(opts.limit)}).
65537
65946
  `)
65538
65947
  );
65539
65948
  process.exit(2);
65540
65949
  }
65541
65950
  if (n2 > SERVER_MAX_LIMIT) {
65542
65951
  process.stderr.write(
65543
- import_picocolors15.default.red(
65952
+ import_picocolors16.default.red(
65544
65953
  `\u2715 --limit max is ${SERVER_MAX_LIMIT} (the server's wallet://history hard cap). Got ${n2}.
65545
65954
  `
65546
65955
  )
@@ -65549,39 +65958,39 @@ async function history(opts) {
65549
65958
  }
65550
65959
  limit = n2;
65551
65960
  }
65552
- const jsonMode3 = opts.json === true;
65961
+ const jsonMode4 = opts.json === true;
65553
65962
  const outcome = await callWithAutoRelogin({
65554
65963
  profile,
65555
65964
  profileName,
65556
- jsonMode: jsonMode3,
65557
- ttyHeader: import_picocolors15.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
65965
+ jsonMode: jsonMode4,
65966
+ ttyHeader: import_picocolors16.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
65558
65967
  fn: (bearer, origin) => apiFetch(
65559
65968
  `/api/history?limit=${encodeURIComponent(String(limit))}`,
65560
65969
  { bearer, origin }
65561
65970
  )
65562
65971
  });
65563
65972
  if (outcome.kind === "auth_failed") {
65564
- if (jsonMode3) {
65973
+ if (jsonMode4) {
65565
65974
  process.stdout.write(
65566
65975
  JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
65567
65976
  );
65568
65977
  process.exit(1);
65569
65978
  }
65570
- process.stderr.write(import_picocolors15.default.red(`\u2715 ${outcome.reason}.
65979
+ process.stderr.write(import_picocolors16.default.red(`\u2715 ${outcome.reason}.
65571
65980
  `));
65572
65981
  process.exit(1);
65573
65982
  }
65574
65983
  if (outcome.kind === "error") {
65575
65984
  const err = outcome.error;
65576
65985
  if (err instanceof ApiError) {
65577
- process.stderr.write(import_picocolors15.default.red(`\u2715 ${err.message} (HTTP ${err.status})
65986
+ process.stderr.write(import_picocolors16.default.red(`\u2715 ${err.message} (HTTP ${err.status})
65578
65987
  `));
65579
65988
  process.exit(1);
65580
65989
  }
65581
65990
  throw err;
65582
65991
  }
65583
65992
  const res = outcome.result;
65584
- if (jsonMode3) {
65993
+ if (jsonMode4) {
65585
65994
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
65586
65995
  return;
65587
65996
  }
@@ -65591,7 +66000,7 @@ async function history(opts) {
65591
66000
  return;
65592
66001
  }
65593
66002
  if (res.txs.length === 0) {
65594
- process.stdout.write(import_picocolors15.default.dim(`No activity yet.
66003
+ process.stdout.write(import_picocolors16.default.dim(`No activity yet.
65595
66004
  `));
65596
66005
  return;
65597
66006
  }
@@ -65611,7 +66020,7 @@ async function history(opts) {
65611
66020
  const colAsset = Math.max(5, ...rows.map((r) => r.asset.length));
65612
66021
  const colTo = Math.max(2, ...rows.map((r) => r.to.length));
65613
66022
  const header = "When".padEnd(colWhen) + " " + "Chain".padEnd(colChain) + " " + "Type".padEnd(colType) + " " + "Amount".padStart(colAmount) + " " + "Asset".padEnd(colAsset) + " " + "To".padEnd(colTo) + " Hash";
65614
- process.stdout.write(import_picocolors15.default.dim(header) + "\n");
66023
+ process.stdout.write(import_picocolors16.default.dim(header) + "\n");
65615
66024
  for (const r of rows) {
65616
66025
  process.stdout.write(
65617
66026
  r.when.padEnd(colWhen) + " " + r.chain.padEnd(colChain) + " " + r.type.padEnd(colType) + " " + r.amount.padStart(colAmount) + " " + r.asset.padEnd(colAsset) + " " + r.to.padEnd(colTo) + " " + r.hash + "\n"
@@ -65619,7 +66028,7 @@ async function history(opts) {
65619
66028
  }
65620
66029
  if (res.fetched_at) {
65621
66030
  process.stdout.write(
65622
- "\n" + import_picocolors15.default.dim(
66031
+ "\n" + import_picocolors16.default.dim(
65623
66032
  `Showing ${rows.length} of limit ${res.limit ?? limit} \xB7 fetched ${res.fetched_at}
65624
66033
  `
65625
66034
  )
@@ -65706,10 +66115,10 @@ function prettyType(activityType, status3) {
65706
66115
  }
65707
66116
 
65708
66117
  // src/commands/swap.ts
65709
- var import_picocolors17 = __toESM(require_picocolors(), 1);
66118
+ var import_picocolors18 = __toESM(require_picocolors(), 1);
65710
66119
 
65711
66120
  // src/lib/intent-flow.ts
65712
- var import_picocolors16 = __toESM(require_picocolors(), 1);
66121
+ var import_picocolors17 = __toESM(require_picocolors(), 1);
65713
66122
  var STREAM_GIVEUP_MS = 10 * 6e4;
65714
66123
  var SOLANA_CHAIN_ID2 = 900;
65715
66124
  function isBlocked2(r) {
@@ -65784,7 +66193,7 @@ async function runIntentFlow(opts) {
65784
66193
  profile: opts.profileName,
65785
66194
  jsonMode: opts.jsonMode,
65786
66195
  origin: activeProfile.mcpOrigin,
65787
- ttyHeader: import_picocolors16.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026")
66196
+ ttyHeader: import_picocolors17.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026")
65788
66197
  });
65789
66198
  } catch (reloginErr) {
65790
66199
  if (opts.jsonMode) {
@@ -65796,7 +66205,7 @@ async function runIntentFlow(opts) {
65796
66205
  process.exit(1);
65797
66206
  }
65798
66207
  process.stderr.write(
65799
- import_picocolors16.default.red(`\u2715 Auto-relogin failed: ${reloginErr.message}
66208
+ import_picocolors17.default.red(`\u2715 Auto-relogin failed: ${reloginErr.message}
65800
66209
  `)
65801
66210
  );
65802
66211
  process.exit(1);
@@ -65820,7 +66229,7 @@ async function runIntentFlow(opts) {
65820
66229
  process.exit(1);
65821
66230
  }
65822
66231
  process.stderr.write(
65823
- import_picocolors16.default.red(`\u2715 ${retryErr.message} (HTTP ${retryErr.status})
66232
+ import_picocolors17.default.red(`\u2715 ${retryErr.message} (HTTP ${retryErr.status})
65824
66233
  `)
65825
66234
  );
65826
66235
  process.exit(1);
@@ -65837,7 +66246,7 @@ async function runIntentFlow(opts) {
65837
66246
  });
65838
66247
  process.exit(1);
65839
66248
  }
65840
- process.stderr.write(import_picocolors16.default.red(`\u2715 ${err.message} (HTTP ${err.status})
66249
+ process.stderr.write(import_picocolors17.default.red(`\u2715 ${err.message} (HTTP ${err.status})
65841
66250
  `));
65842
66251
  process.exit(1);
65843
66252
  } else {
@@ -65859,18 +66268,18 @@ async function runIntentFlow(opts) {
65859
66268
  });
65860
66269
  process.exit(1);
65861
66270
  }
65862
- process.stderr.write(import_picocolors16.default.red(`\u2715 Blocked (${proposed.code}): ${proposed.reason}
66271
+ process.stderr.write(import_picocolors17.default.red(`\u2715 Blocked (${proposed.code}): ${proposed.reason}
65863
66272
  `));
65864
66273
  if (proposed.upgrade_url) {
65865
66274
  process.stderr.write(
65866
66275
  ` Open this to grant access, then re-run the command:
65867
- ${import_picocolors16.default.cyan(proposed.upgrade_url)}
66276
+ ${import_picocolors17.default.cyan(proposed.upgrade_url)}
65868
66277
  `
65869
66278
  );
65870
66279
  }
65871
66280
  if (proposed.recommended_actions && proposed.recommended_actions.length > 0) {
65872
66281
  process.stderr.write(
65873
- import_picocolors16.default.dim(
66282
+ import_picocolors17.default.dim(
65874
66283
  ` Suggested actions:
65875
66284
  ` + proposed.recommended_actions.map((a) => ` \u2022 ${JSON.stringify(a)}`).join("\n") + "\n"
65876
66285
  )
@@ -65893,8 +66302,8 @@ async function runIntentFlow(opts) {
65893
66302
  } else {
65894
66303
  process.stdout.write(
65895
66304
  `
65896
- ${import_picocolors16.default.bold("Proposed.")} Open this URL to approve with biometric:
65897
- ${import_picocolors16.default.cyan(proposed.approval_url)}
66305
+ ${import_picocolors17.default.bold("Proposed.")} Open this URL to approve with biometric:
66306
+ ${import_picocolors17.default.cyan(proposed.approval_url)}
65898
66307
 
65899
66308
  `
65900
66309
  );
@@ -65916,7 +66325,7 @@ ${import_picocolors16.default.bold("Proposed.")} Open this URL to approve with b
65916
66325
  if (opts.jsonMode) {
65917
66326
  emitNdjson2({ status: s.status, intent_id: s.approval_id });
65918
66327
  } else {
65919
- process.stdout.write(` ${describeStatus2(s.status)}${import_picocolors16.default.dim("\u2026")}\r`);
66328
+ process.stdout.write(` ${describeStatus2(s.status)}${import_picocolors17.default.dim("\u2026")}\r`);
65920
66329
  }
65921
66330
  }
65922
66331
  });
@@ -65930,7 +66339,7 @@ ${import_picocolors16.default.bold("Proposed.")} Open this URL to approve with b
65930
66339
  profile: opts.profileName,
65931
66340
  jsonMode: opts.jsonMode,
65932
66341
  origin: activeProfile.mcpOrigin,
65933
- ttyHeader: import_picocolors16.default.dim(
66342
+ ttyHeader: import_picocolors17.default.dim(
65934
66343
  "Bearer expired mid-poll \u2014 re-pairing this terminal\u2026"
65935
66344
  )
65936
66345
  });
@@ -65945,7 +66354,7 @@ ${import_picocolors16.default.bold("Proposed.")} Open this URL to approve with b
65945
66354
  process.exit(1);
65946
66355
  }
65947
66356
  process.stderr.write(
65948
- "\n" + import_picocolors16.default.red(`\u2715 Auto-relogin failed: ${reloginErr.message}
66357
+ "\n" + import_picocolors17.default.red(`\u2715 Auto-relogin failed: ${reloginErr.message}
65949
66358
  `)
65950
66359
  );
65951
66360
  process.exit(1);
@@ -65963,7 +66372,7 @@ ${import_picocolors16.default.bold("Proposed.")} Open this URL to approve with b
65963
66372
  process.exit(1);
65964
66373
  }
65965
66374
  process.stderr.write(
65966
- "\n" + import_picocolors16.default.red(`\u2715 Status poll failed: ${retryErr.message}
66375
+ "\n" + import_picocolors17.default.red(`\u2715 Status poll failed: ${retryErr.message}
65967
66376
  `)
65968
66377
  );
65969
66378
  process.exit(1);
@@ -65979,7 +66388,7 @@ ${import_picocolors16.default.bold("Proposed.")} Open this URL to approve with b
65979
66388
  process.exit(1);
65980
66389
  }
65981
66390
  process.stderr.write(
65982
- "\n" + import_picocolors16.default.red(`\u2715 Status poll failed: ${err.message}
66391
+ "\n" + import_picocolors17.default.red(`\u2715 Status poll failed: ${err.message}
65983
66392
  `)
65984
66393
  );
65985
66394
  process.exit(1);
@@ -66020,39 +66429,39 @@ ${import_picocolors16.default.bold("Proposed.")} Open this URL to approve with b
66020
66429
  process.stdout.write("\n");
66021
66430
  const printLegJournal = () => {
66022
66431
  if (legs.length === 0) return;
66023
- process.stdout.write(import_picocolors16.default.bold(" Legs:\n"));
66432
+ process.stdout.write(import_picocolors17.default.bold(" Legs:\n"));
66024
66433
  for (const l of legs) {
66025
- const line = l.status === "mined" ? import_picocolors16.default.green(`\u2713 leg ${l.index + 1} mined`) + (l.tx_hash ? import_picocolors16.default.dim(` ${l.tx_hash}`) : "") : l.status === "failed" ? import_picocolors16.default.red(`\u2715 leg ${l.index + 1} failed`) + (l.failure?.message ? ` \u2014 ${l.failure.message}` : "") : l.status === "pending" || l.status === "rendered" ? import_picocolors16.default.dim(`\u2013 leg ${l.index + 1} not run`) : import_picocolors16.default.dim(`\u2026 leg ${l.index + 1} ${l.status}`);
66434
+ const line = l.status === "mined" ? import_picocolors17.default.green(`\u2713 leg ${l.index + 1} mined`) + (l.tx_hash ? import_picocolors17.default.dim(` ${l.tx_hash}`) : "") : l.status === "failed" ? import_picocolors17.default.red(`\u2715 leg ${l.index + 1} failed`) + (l.failure?.message ? ` \u2014 ${l.failure.message}` : "") : l.status === "pending" || l.status === "rendered" ? import_picocolors17.default.dim(`\u2013 leg ${l.index + 1} not run`) : import_picocolors17.default.dim(`\u2026 leg ${l.index + 1} ${l.status}`);
66026
66435
  process.stdout.write(` ${line}
66027
66436
  `);
66028
66437
  }
66029
66438
  };
66030
66439
  if (final.status === "mined") {
66031
- process.stdout.write(import_picocolors16.default.green("\u2713 Mined.") + "\n");
66440
+ process.stdout.write(import_picocolors17.default.green("\u2713 Mined.") + "\n");
66032
66441
  if (final.tx_hash) {
66033
66442
  process.stdout.write(` Tx ${final.tx_hash}
66034
66443
  `);
66035
66444
  }
66036
66445
  if (explorer) {
66037
- process.stdout.write(` Explorer ${import_picocolors16.default.cyan(explorer)}
66446
+ process.stdout.write(` Explorer ${import_picocolors17.default.cyan(explorer)}
66038
66447
  `);
66039
66448
  }
66040
66449
  printLegJournal();
66041
66450
  process.exit(0);
66042
66451
  }
66043
66452
  if (final.status === "failed" && failure?.message) {
66044
- process.stderr.write(import_picocolors16.default.red(`\u2715 ${failure.message}
66453
+ process.stderr.write(import_picocolors17.default.red(`\u2715 ${failure.message}
66045
66454
  `));
66046
66455
  if (retryCommand) {
66047
66456
  process.stderr.write(` Retry:
66048
- ${import_picocolors16.default.cyan(retryCommand)}
66457
+ ${import_picocolors17.default.cyan(retryCommand)}
66049
66458
  `);
66050
66459
  }
66051
66460
  printLegJournal();
66052
66461
  process.exit(1);
66053
66462
  }
66054
66463
  const label = final.status === "rejected" ? "Rejected by user" : final.status === "expired" ? "Expired (TTL elapsed before approval)" : final.status === "failed" ? "The transaction did not land; nothing moved. Re-run the command to retry with fresh parameters" : `Ended in unexpected status: ${final.status}`;
66055
- process.stderr.write(import_picocolors16.default.red(`\u2715 ${label}.
66464
+ process.stderr.write(import_picocolors17.default.red(`\u2715 ${label}.
66056
66465
  `));
66057
66466
  printLegJournal();
66058
66467
  process.exit(1);
@@ -66072,7 +66481,7 @@ function isAsset(v) {
66072
66481
  return ASSET_VALUES.has(v.toLowerCase());
66073
66482
  }
66074
66483
  function failArg(msg) {
66075
- process.stderr.write(import_picocolors17.default.red(`\u2715 ${msg}
66484
+ process.stderr.write(import_picocolors18.default.red(`\u2715 ${msg}
66076
66485
  `));
66077
66486
  process.exit(2);
66078
66487
  }
@@ -66080,24 +66489,24 @@ async function swap(amount, fromAsset, opts) {
66080
66489
  const requested = opts.profile ?? DEFAULT_PROFILE;
66081
66490
  const resolved = await resolveProfile(requested);
66082
66491
  if (!resolved) {
66083
- process.stderr.write(import_picocolors17.default.red("Not logged in. Run agentgates login first.\n"));
66492
+ process.stderr.write(import_picocolors18.default.red("Not logged in. Run agentgates login first.\n"));
66084
66493
  process.exit(2);
66085
66494
  }
66086
66495
  if (resolved.autoSelected) {
66087
- process.stderr.write(import_picocolors17.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
66496
+ process.stderr.write(import_picocolors18.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
66088
66497
  `));
66089
66498
  }
66090
66499
  const { profile, name: profileName } = resolved;
66091
66500
  const stdoutIsTty = process.stdout.isTTY === true;
66092
- const jsonMode3 = opts.json === true || !stdoutIsTty;
66501
+ const jsonMode4 = opts.json === true || !stdoutIsTty;
66093
66502
  const amountNumber = Number(amount);
66094
66503
  if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
66095
- failArg(`amount must be a positive number (got ${import_picocolors17.default.bold(amount)}).`);
66504
+ failArg(`amount must be a positive number (got ${import_picocolors18.default.bold(amount)}).`);
66096
66505
  }
66097
66506
  const fromAssetNorm = fromAsset.toLowerCase();
66098
66507
  if (!isAsset(fromAssetNorm)) {
66099
66508
  failArg(
66100
- `from-asset must be ${import_picocolors17.default.bold("native")} or ${import_picocolors17.default.bold("usdc")} (got ${import_picocolors17.default.bold(fromAsset)}).`
66509
+ `from-asset must be ${import_picocolors18.default.bold("native")} or ${import_picocolors18.default.bold("usdc")} (got ${import_picocolors18.default.bold(fromAsset)}).`
66101
66510
  );
66102
66511
  }
66103
66512
  if (!opts.toAsset) {
@@ -66106,7 +66515,7 @@ async function swap(amount, fromAsset, opts) {
66106
66515
  const toAssetNorm = opts.toAsset.toLowerCase();
66107
66516
  if (!isAsset(toAssetNorm)) {
66108
66517
  failArg(
66109
- `--to-asset must be ${import_picocolors17.default.bold("native")} or ${import_picocolors17.default.bold("usdc")} (got ${import_picocolors17.default.bold(opts.toAsset)}).`
66518
+ `--to-asset must be ${import_picocolors18.default.bold("native")} or ${import_picocolors18.default.bold("usdc")} (got ${import_picocolors18.default.bold(opts.toAsset)}).`
66110
66519
  );
66111
66520
  }
66112
66521
  if (!opts.userStated || opts.userStated.trim() === "") {
@@ -66228,16 +66637,16 @@ async function swap(amount, fromAsset, opts) {
66228
66637
  body: proposeBody,
66229
66638
  profileName,
66230
66639
  initialProfile: profile,
66231
- jsonMode: jsonMode3,
66640
+ jsonMode: jsonMode4,
66232
66641
  shouldOpenBrowser,
66233
66642
  buildRetryCommand
66234
66643
  });
66235
66644
  }
66236
66645
 
66237
66646
  // src/commands/batch.ts
66238
- var import_picocolors18 = __toESM(require_picocolors(), 1);
66647
+ var import_picocolors19 = __toESM(require_picocolors(), 1);
66239
66648
  function failArg2(msg) {
66240
- process.stderr.write(import_picocolors18.default.red(`\u2715 ${msg}
66649
+ process.stderr.write(import_picocolors19.default.red(`\u2715 ${msg}
66241
66650
  `));
66242
66651
  process.exit(2);
66243
66652
  }
@@ -66245,11 +66654,11 @@ async function batch(opts) {
66245
66654
  const requested = opts.profile ?? DEFAULT_PROFILE;
66246
66655
  const resolved = await resolveProfile(requested);
66247
66656
  if (!resolved) {
66248
- process.stderr.write(import_picocolors18.default.red("Not logged in. Run agentgates login first.\n"));
66657
+ process.stderr.write(import_picocolors19.default.red("Not logged in. Run agentgates login first.\n"));
66249
66658
  process.exit(2);
66250
66659
  }
66251
66660
  const { name: profileName, profile } = resolved;
66252
- const jsonMode3 = opts.json === true || !process.stdout.isTTY;
66661
+ const jsonMode4 = opts.json === true || !process.stdout.isTTY;
66253
66662
  let legs;
66254
66663
  try {
66255
66664
  legs = JSON.parse(opts.legsJson);
@@ -66293,20 +66702,20 @@ async function batch(opts) {
66293
66702
  },
66294
66703
  profileName,
66295
66704
  initialProfile: profile,
66296
- jsonMode: jsonMode3,
66705
+ jsonMode: jsonMode4,
66297
66706
  shouldOpenBrowser
66298
66707
  });
66299
66708
  }
66300
66709
 
66301
66710
  // src/commands/fund-wallet.ts
66302
- var import_picocolors19 = __toESM(require_picocolors(), 1);
66711
+ var import_picocolors20 = __toESM(require_picocolors(), 1);
66303
66712
  var EVM_ADDRESS_RE2 = /^0x[0-9a-fA-F]{40}$/;
66304
66713
  var SOLANA_ADDRESS_RE2 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
66305
66714
  function isAddressTarget(target) {
66306
66715
  return EVM_ADDRESS_RE2.test(target) || SOLANA_ADDRESS_RE2.test(target);
66307
66716
  }
66308
66717
  function failArg3(msg) {
66309
- process.stderr.write(import_picocolors19.default.red(`\u2715 ${msg}
66718
+ process.stderr.write(import_picocolors20.default.red(`\u2715 ${msg}
66310
66719
  `));
66311
66720
  process.exit(2);
66312
66721
  }
@@ -66314,11 +66723,11 @@ async function fundWallet(address, opts) {
66314
66723
  const requested = opts.profile ?? DEFAULT_PROFILE;
66315
66724
  const resolved = await resolveProfile(requested);
66316
66725
  if (!resolved) {
66317
- process.stderr.write(import_picocolors19.default.red("Not logged in. Run agentgates login first.\n"));
66726
+ process.stderr.write(import_picocolors20.default.red("Not logged in. Run agentgates login first.\n"));
66318
66727
  process.exit(2);
66319
66728
  }
66320
66729
  const { name: profileName, profile } = resolved;
66321
- const jsonMode3 = opts.json === true || !process.stdout.isTTY;
66730
+ const jsonMode4 = opts.json === true || !process.stdout.isTTY;
66322
66731
  if (!opts.chain) {
66323
66732
  failArg3("--chain is required (1/137/8453/42161/900 or shortName).");
66324
66733
  }
@@ -66370,7 +66779,7 @@ async function fundWallet(address, opts) {
66370
66779
  },
66371
66780
  profileName,
66372
66781
  initialProfile: profile,
66373
- jsonMode: jsonMode3,
66782
+ jsonMode: jsonMode4,
66374
66783
  shouldOpenBrowser
66375
66784
  });
66376
66785
  }
@@ -66385,17 +66794,17 @@ async function fundWallet(address, opts) {
66385
66794
  },
66386
66795
  profileName,
66387
66796
  initialProfile: profile,
66388
- jsonMode: jsonMode3,
66797
+ jsonMode: jsonMode4,
66389
66798
  shouldOpenBrowser
66390
66799
  });
66391
66800
  }
66392
66801
 
66393
66802
  // src/commands/earn-supply.ts
66394
- var import_picocolors20 = __toESM(require_picocolors(), 1);
66803
+ var import_picocolors21 = __toESM(require_picocolors(), 1);
66395
66804
  var ASSET_VALUES2 = /* @__PURE__ */ new Set(["native", "usdc"]);
66396
66805
  var PROTOCOLS = /* @__PURE__ */ new Set(["aave_v3", "kamino_lend"]);
66397
66806
  function failArg4(msg) {
66398
- process.stderr.write(import_picocolors20.default.red(`\u2715 ${msg}
66807
+ process.stderr.write(import_picocolors21.default.red(`\u2715 ${msg}
66399
66808
  `));
66400
66809
  process.exit(2);
66401
66810
  }
@@ -66403,24 +66812,24 @@ async function earnSupply(amount, asset, opts) {
66403
66812
  const requested = opts.profile ?? DEFAULT_PROFILE;
66404
66813
  const resolved = await resolveProfile(requested);
66405
66814
  if (!resolved) {
66406
- process.stderr.write(import_picocolors20.default.red("Not logged in. Run agentgates login first.\n"));
66815
+ process.stderr.write(import_picocolors21.default.red("Not logged in. Run agentgates login first.\n"));
66407
66816
  process.exit(2);
66408
66817
  }
66409
66818
  if (resolved.autoSelected) {
66410
- process.stderr.write(import_picocolors20.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
66819
+ process.stderr.write(import_picocolors21.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
66411
66820
  `));
66412
66821
  }
66413
66822
  const { profile, name: profileName } = resolved;
66414
66823
  const stdoutIsTty = process.stdout.isTTY === true;
66415
- const jsonMode3 = opts.json === true || !stdoutIsTty;
66824
+ const jsonMode4 = opts.json === true || !stdoutIsTty;
66416
66825
  const amountNumber = Number(amount);
66417
66826
  if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
66418
- failArg4(`amount must be a positive number (got ${import_picocolors20.default.bold(amount)}).`);
66827
+ failArg4(`amount must be a positive number (got ${import_picocolors21.default.bold(amount)}).`);
66419
66828
  }
66420
66829
  const assetNorm = asset.toLowerCase();
66421
66830
  if (!ASSET_VALUES2.has(assetNorm)) {
66422
66831
  failArg4(
66423
- `asset must be ${import_picocolors20.default.bold("native")} or ${import_picocolors20.default.bold("usdc")} (got ${import_picocolors20.default.bold(asset)}).`
66832
+ `asset must be ${import_picocolors21.default.bold("native")} or ${import_picocolors21.default.bold("usdc")} (got ${import_picocolors21.default.bold(asset)}).`
66424
66833
  );
66425
66834
  }
66426
66835
  if (!opts.chain) {
@@ -66432,7 +66841,7 @@ async function earnSupply(amount, asset, opts) {
66432
66841
  const protocolNorm = opts.protocol.toLowerCase();
66433
66842
  if (!PROTOCOLS.has(protocolNorm)) {
66434
66843
  failArg4(
66435
- `--protocol must be ${import_picocolors20.default.bold("aave_v3")} or ${import_picocolors20.default.bold("kamino_lend")} (got ${import_picocolors20.default.bold(opts.protocol)}).`
66844
+ `--protocol must be ${import_picocolors21.default.bold("aave_v3")} or ${import_picocolors21.default.bold("kamino_lend")} (got ${import_picocolors21.default.bold(opts.protocol)}).`
66436
66845
  );
66437
66846
  }
66438
66847
  if (!opts.userStated || opts.userStated.trim() === "") {
@@ -66478,17 +66887,17 @@ async function earnSupply(amount, asset, opts) {
66478
66887
  body: proposeBody,
66479
66888
  profileName,
66480
66889
  initialProfile: profile,
66481
- jsonMode: jsonMode3,
66890
+ jsonMode: jsonMode4,
66482
66891
  shouldOpenBrowser
66483
66892
  });
66484
66893
  }
66485
66894
 
66486
66895
  // src/commands/earn-withdraw.ts
66487
- var import_picocolors21 = __toESM(require_picocolors(), 1);
66896
+ var import_picocolors22 = __toESM(require_picocolors(), 1);
66488
66897
  var ASSET_VALUES3 = /* @__PURE__ */ new Set(["native", "usdc"]);
66489
66898
  var PROTOCOLS2 = /* @__PURE__ */ new Set(["aave_v3", "kamino_lend"]);
66490
66899
  function failArg5(msg) {
66491
- process.stderr.write(import_picocolors21.default.red(`\u2715 ${msg}
66900
+ process.stderr.write(import_picocolors22.default.red(`\u2715 ${msg}
66492
66901
  `));
66493
66902
  process.exit(2);
66494
66903
  }
@@ -66496,29 +66905,29 @@ async function earnWithdraw(amountOrMax, asset, opts) {
66496
66905
  const requested = opts.profile ?? DEFAULT_PROFILE;
66497
66906
  const resolved = await resolveProfile(requested);
66498
66907
  if (!resolved) {
66499
- process.stderr.write(import_picocolors21.default.red("Not logged in. Run agentgates login first.\n"));
66908
+ process.stderr.write(import_picocolors22.default.red("Not logged in. Run agentgates login first.\n"));
66500
66909
  process.exit(2);
66501
66910
  }
66502
66911
  if (resolved.autoSelected) {
66503
- process.stderr.write(import_picocolors21.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
66912
+ process.stderr.write(import_picocolors22.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
66504
66913
  `));
66505
66914
  }
66506
66915
  const { profile, name: profileName } = resolved;
66507
66916
  const stdoutIsTty = process.stdout.isTTY === true;
66508
- const jsonMode3 = opts.json === true || !stdoutIsTty;
66917
+ const jsonMode4 = opts.json === true || !stdoutIsTty;
66509
66918
  const isMax = amountOrMax.toLowerCase() === "max";
66510
66919
  if (!isMax) {
66511
66920
  const amountNumber = Number(amountOrMax);
66512
66921
  if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
66513
66922
  failArg5(
66514
- `<amount-or-max> must be a positive number or the literal string "max" (got ${import_picocolors21.default.bold(amountOrMax)}).`
66923
+ `<amount-or-max> must be a positive number or the literal string "max" (got ${import_picocolors22.default.bold(amountOrMax)}).`
66515
66924
  );
66516
66925
  }
66517
66926
  }
66518
66927
  const assetNorm = asset.toLowerCase();
66519
66928
  if (!ASSET_VALUES3.has(assetNorm)) {
66520
66929
  failArg5(
66521
- `asset must be ${import_picocolors21.default.bold("native")} or ${import_picocolors21.default.bold("usdc")} (got ${import_picocolors21.default.bold(asset)}).`
66930
+ `asset must be ${import_picocolors22.default.bold("native")} or ${import_picocolors22.default.bold("usdc")} (got ${import_picocolors22.default.bold(asset)}).`
66522
66931
  );
66523
66932
  }
66524
66933
  if (!opts.chain) {
@@ -66530,7 +66939,7 @@ async function earnWithdraw(amountOrMax, asset, opts) {
66530
66939
  const protocolNorm = opts.protocol.toLowerCase();
66531
66940
  if (!PROTOCOLS2.has(protocolNorm)) {
66532
66941
  failArg5(
66533
- `--protocol must be ${import_picocolors21.default.bold("aave_v3")} or ${import_picocolors21.default.bold("kamino_lend")} (got ${import_picocolors21.default.bold(opts.protocol)}).`
66942
+ `--protocol must be ${import_picocolors22.default.bold("aave_v3")} or ${import_picocolors22.default.bold("kamino_lend")} (got ${import_picocolors22.default.bold(opts.protocol)}).`
66534
66943
  );
66535
66944
  }
66536
66945
  if (!opts.userStated || opts.userStated.trim() === "") {
@@ -66576,13 +66985,13 @@ async function earnWithdraw(amountOrMax, asset, opts) {
66576
66985
  body: proposeBody,
66577
66986
  profileName,
66578
66987
  initialProfile: profile,
66579
- jsonMode: jsonMode3,
66988
+ jsonMode: jsonMode4,
66580
66989
  shouldOpenBrowser
66581
66990
  });
66582
66991
  }
66583
66992
 
66584
66993
  // src/commands/eat.ts
66585
- var import_picocolors22 = __toESM(require_picocolors(), 1);
66994
+ var import_picocolors23 = __toESM(require_picocolors(), 1);
66586
66995
  function parseLineJson(values) {
66587
66996
  const lines = [];
66588
66997
  for (const value of values) {
@@ -66609,27 +67018,27 @@ function parseLineJson(values) {
66609
67018
  async function loadResolvedProfile(requested) {
66610
67019
  const resolved = await resolveProfile(requested);
66611
67020
  if (!resolved) {
66612
- process.stderr.write(import_picocolors22.default.red("Not logged in. Run agentgates login first.\n"));
67021
+ process.stderr.write(import_picocolors23.default.red("Not logged in. Run agentgates login first.\n"));
66613
67022
  process.exit(2);
66614
67023
  }
66615
67024
  if (resolved.autoSelected) {
66616
- process.stderr.write(import_picocolors22.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
67025
+ process.stderr.write(import_picocolors23.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
66617
67026
  `));
66618
67027
  }
66619
67028
  return resolved;
66620
67029
  }
66621
- function printResult(res, jsonMode3) {
66622
- if (jsonMode3) {
67030
+ function printResult(res, jsonMode4) {
67031
+ if (jsonMode4) {
66623
67032
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
66624
67033
  return;
66625
67034
  }
66626
67035
  if (res.blocked) {
66627
- process.stderr.write(import_picocolors22.default.red(`\u2715 ${res.reason ?? res.code ?? "Blocked"}
67036
+ process.stderr.write(import_picocolors23.default.red(`\u2715 ${res.reason ?? res.code ?? "Blocked"}
66628
67037
  `));
66629
67038
  if (res.upgrade_url) {
66630
67039
  process.stderr.write(
66631
67040
  ` Open this to grant access, then re-run the command:
66632
- ${import_picocolors22.default.cyan(res.upgrade_url)}
67041
+ ${import_picocolors23.default.cyan(res.upgrade_url)}
66633
67042
  `
66634
67043
  );
66635
67044
  }
@@ -66655,35 +67064,35 @@ async function postRestaurantQuiet(path6, body, resolved) {
66655
67064
  return null;
66656
67065
  }
66657
67066
  }
66658
- async function postRestaurant(path6, body, resolved, jsonMode3) {
67067
+ async function postRestaurant(path6, body, resolved, jsonMode4) {
66659
67068
  const outcome = await callWithAutoRelogin({
66660
67069
  profile: resolved.profile,
66661
67070
  profileName: resolved.name,
66662
- jsonMode: jsonMode3,
66663
- ttyHeader: import_picocolors22.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
67071
+ jsonMode: jsonMode4,
67072
+ ttyHeader: import_picocolors23.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
66664
67073
  fn: (bearer, origin) => apiFetch(path6, { method: "POST", bearer, origin, body })
66665
67074
  });
66666
67075
  if (outcome.kind === "auth_failed") {
66667
- if (jsonMode3) {
67076
+ if (jsonMode4) {
66668
67077
  process.stdout.write(
66669
67078
  JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
66670
67079
  );
66671
67080
  process.exit(1);
66672
67081
  }
66673
- process.stderr.write(import_picocolors22.default.red(`\u2715 ${outcome.reason}.
67082
+ process.stderr.write(import_picocolors23.default.red(`\u2715 ${outcome.reason}.
66674
67083
  `));
66675
67084
  process.exit(1);
66676
67085
  }
66677
67086
  if (outcome.kind === "error") {
66678
67087
  const err = outcome.error;
66679
67088
  if (err instanceof ApiError) {
66680
- if (jsonMode3) {
67089
+ if (jsonMode4) {
66681
67090
  process.stdout.write(
66682
67091
  JSON.stringify({ ok: false, status: "request_failed", error: err.message, http_status: err.status }) + "\n"
66683
67092
  );
66684
67093
  process.exit(1);
66685
67094
  }
66686
- process.stderr.write(import_picocolors22.default.red(`\u2715 ${err.message} (HTTP ${err.status})
67095
+ process.stderr.write(import_picocolors23.default.red(`\u2715 ${err.message} (HTTP ${err.status})
66687
67096
  `));
66688
67097
  process.exit(1);
66689
67098
  }
@@ -66693,10 +67102,10 @@ async function postRestaurant(path6, body, resolved, jsonMode3) {
66693
67102
  }
66694
67103
  async function searchFood(opts) {
66695
67104
  const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
66696
- const jsonMode3 = opts.json === true || process.stdout.isTTY !== true;
67105
+ const jsonMode4 = opts.json === true || process.stdout.isTTY !== true;
66697
67106
  if (!opts.location && !opts.name) {
66698
67107
  process.stderr.write(
66699
- import_picocolors22.default.red("\u2715 Pass --location (search near a place) or --name (look one store up).\n")
67108
+ import_picocolors23.default.red("\u2715 Pass --location (search near a place) or --name (look one store up).\n")
66700
67109
  );
66701
67110
  process.exit(2);
66702
67111
  }
@@ -66709,15 +67118,15 @@ async function searchFood(opts) {
66709
67118
  if (opts.radiusMiles !== void 0) body.radius_miles = Number(opts.radiusMiles);
66710
67119
  if (opts.openOnly !== void 0) body.open_only = opts.openOnly;
66711
67120
  if (opts.limit !== void 0) body.limit = Number(opts.limit);
66712
- const result = await postRestaurant("/api/restaurants/search", body, resolved, jsonMode3);
66713
- if (result) printResult(result, jsonMode3);
67121
+ const result = await postRestaurant("/api/restaurants/search", body, resolved, jsonMode4);
67122
+ if (result) printResult(result, jsonMode4);
66714
67123
  }
66715
67124
  async function menuFood(items, opts) {
66716
67125
  const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
66717
- const jsonMode3 = opts.json === true || process.stdout.isTTY !== true;
67126
+ const jsonMode4 = opts.json === true || process.stdout.isTTY !== true;
66718
67127
  if (!opts.brand || !opts.address) {
66719
67128
  process.stderr.write(
66720
- import_picocolors22.default.red(
67129
+ import_picocolors23.default.red(
66721
67130
  "\u2715 --brand and --address are required \u2014 use the pair a `agentgates eat search` result gave you, verbatim.\n"
66722
67131
  )
66723
67132
  );
@@ -66729,15 +67138,15 @@ async function menuFood(items, opts) {
66729
67138
  intent: opts.intent,
66730
67139
  items: items ?? []
66731
67140
  };
66732
- const result = await postRestaurant("/api/restaurants/menu", body, resolved, jsonMode3);
66733
- if (result) printResult(result, jsonMode3);
67141
+ const result = await postRestaurant("/api/restaurants/menu", body, resolved, jsonMode4);
67142
+ if (result) printResult(result, jsonMode4);
66734
67143
  }
66735
67144
  async function orderFood(items, opts) {
66736
67145
  const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
66737
- const jsonMode3 = opts.json === true || process.stdout.isTTY !== true;
67146
+ const jsonMode4 = opts.json === true || process.stdout.isTTY !== true;
66738
67147
  if (!opts.brand || !opts.address) {
66739
67148
  process.stderr.write(
66740
- import_picocolors22.default.red(
67149
+ import_picocolors23.default.red(
66741
67150
  "\u2715 --brand and --address are required \u2014 use the pair a `agentgates eat search` result gave you, verbatim.\n"
66742
67151
  )
66743
67152
  );
@@ -66747,14 +67156,14 @@ async function orderFood(items, opts) {
66747
67156
  try {
66748
67157
  structuredLines = parseLineJson(opts.lineJson ?? []);
66749
67158
  } catch (e) {
66750
- process.stderr.write(import_picocolors22.default.red(`\u2715 ${e instanceof Error ? e.message : String(e)}
67159
+ process.stderr.write(import_picocolors23.default.red(`\u2715 ${e instanceof Error ? e.message : String(e)}
66751
67160
  `));
66752
67161
  process.exit(2);
66753
67162
  }
66754
67163
  const lines = [...items ?? [], ...structuredLines];
66755
67164
  if (lines.length === 0) {
66756
67165
  process.stderr.write(
66757
- import_picocolors22.default.red("\u2715 Pass at least one dish \u2014 plain words as arguments, or --line-json for a line with a size/option/note.\n")
67166
+ import_picocolors23.default.red("\u2715 Pass at least one dish \u2014 plain words as arguments, or --line-json for a line with a size/option/note.\n")
66758
67167
  );
66759
67168
  process.exit(2);
66760
67169
  }
@@ -66765,9 +67174,9 @@ async function orderFood(items, opts) {
66765
67174
  fulfillment: opts.fulfillment,
66766
67175
  intent: opts.intent
66767
67176
  };
66768
- const result = await postRestaurant("/api/restaurants/order", body, resolved, jsonMode3);
67177
+ const result = await postRestaurant("/api/restaurants/order", body, resolved, jsonMode4);
66769
67178
  if (!result) return;
66770
- printResult(result, jsonMode3);
67179
+ printResult(result, jsonMode4);
66771
67180
  const approvalUrl = typeof result.approval_url === "string" ? result.approval_url : null;
66772
67181
  const browserAllowed = (() => {
66773
67182
  if (opts.browserMode === "open") return true;
@@ -66786,9 +67195,9 @@ async function orderFood(items, opts) {
66786
67195
  return;
66787
67196
  }
66788
67197
  if (!agentCard.will_attempt) {
66789
- if (!jsonMode3) {
67198
+ if (!jsonMode4) {
66790
67199
  process.stderr.write(
66791
- import_picocolors22.default.yellow(
67200
+ import_picocolors23.default.yellow(
66792
67201
  `This order is over your saved card's per-order cap (${fmtCents(agentCard.max_per_order_cents)}), so it needs you.
66793
67202
  `
66794
67203
  )
@@ -66797,15 +67206,15 @@ async function orderFood(items, opts) {
66797
67206
  openApproval();
66798
67207
  return;
66799
67208
  }
66800
- const verdict = await pollOrderVerdict(orderId, resolved, jsonMode3);
66801
- if (jsonMode3) {
67209
+ const verdict = await pollOrderVerdict(orderId, resolved, jsonMode4);
67210
+ if (jsonMode4) {
66802
67211
  process.stdout.write(JSON.stringify(verdict) + "\n");
66803
67212
  if (verdict.status === "failed") return;
66804
67213
  return;
66805
67214
  }
66806
67215
  if (verdict.status === "paid") {
66807
67216
  process.stdout.write(
66808
- import_picocolors22.default.green(
67217
+ import_picocolors23.default.green(
66809
67218
  `Paid with your saved card ending ${agentCard.last4}.` + (verdict.failure_detail ? ` ${verdict.failure_detail}` : "") + " Nothing to do.\n"
66810
67219
  )
66811
67220
  );
@@ -66813,7 +67222,7 @@ async function orderFood(items, opts) {
66813
67222
  }
66814
67223
  if (verdict.status === "failed") {
66815
67224
  process.stderr.write(
66816
- import_picocolors22.default.yellow(
67225
+ import_picocolors23.default.yellow(
66817
67226
  `Your saved card did not pay this (${verdict.failure_reason ?? "refused"}${verdict.failure_detail ? `: ${verdict.failure_detail}` : ""}). Nothing was charged. The link still works for you to pay yourself.
66818
67227
  `
66819
67228
  )
@@ -66823,7 +67232,7 @@ async function orderFood(items, opts) {
66823
67232
  }
66824
67233
  if (verdict.status === "unconfirmed") {
66825
67234
  process.stderr.write(
66826
- import_picocolors22.default.red(
67235
+ import_picocolors23.default.red(
66827
67236
  "A payment attempt happened and its outcome is UNKNOWN \u2014 nothing will retry it. Open the order and check before paying anything:\n" + (approvalUrl ? ` ${approvalUrl}
66828
67237
  ` : "")
66829
67238
  )
@@ -66832,7 +67241,7 @@ async function orderFood(items, opts) {
66832
67241
  return;
66833
67242
  }
66834
67243
  process.stderr.write(
66835
- import_picocolors22.default.dim(
67244
+ import_picocolors23.default.dim(
66836
67245
  `Still being attempted. Check with: agentgates eat status ${orderId}` + (approvalUrl ? ` \u2014 or pay yourself: ${approvalUrl}` : "") + "\n"
66837
67246
  )
66838
67247
  );
@@ -66855,9 +67264,9 @@ function fmtCents(cents) {
66855
67264
  }
66856
67265
  var POLL_BUDGET_MS = 1e5;
66857
67266
  var POLL_INTERVAL_MS2 = 3500;
66858
- async function pollOrderVerdict(orderId, resolved, jsonMode3) {
66859
- if (!jsonMode3) {
66860
- process.stderr.write(import_picocolors22.default.dim("Your saved card is paying this \u2014 watching for the result\u2026\n"));
67267
+ async function pollOrderVerdict(orderId, resolved, jsonMode4) {
67268
+ if (!jsonMode4) {
67269
+ process.stderr.write(import_picocolors23.default.dim("Your saved card is paying this \u2014 watching for the result\u2026\n"));
66861
67270
  }
66862
67271
  const deadline = Date.now() + POLL_BUDGET_MS;
66863
67272
  let last = {
@@ -66887,19 +67296,19 @@ async function pollOrderVerdict(orderId, resolved, jsonMode3) {
66887
67296
  }
66888
67297
  async function statusFood(orderId, opts) {
66889
67298
  const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
66890
- const jsonMode3 = opts.json === true || process.stdout.isTTY !== true;
67299
+ const jsonMode4 = opts.json === true || process.stdout.isTTY !== true;
66891
67300
  const result = await postRestaurant(
66892
67301
  "/api/restaurants/order-status",
66893
67302
  { order_id: orderId.trim() },
66894
67303
  resolved,
66895
- jsonMode3
67304
+ jsonMode4
66896
67305
  );
66897
67306
  if (!result) return;
66898
67307
  if (result.blocked) {
66899
- printResult(result, jsonMode3);
67308
+ printResult(result, jsonMode4);
66900
67309
  return;
66901
67310
  }
66902
- if (jsonMode3) {
67311
+ if (jsonMode4) {
66903
67312
  process.stdout.write(JSON.stringify(result, null, 2) + "\n");
66904
67313
  return;
66905
67314
  }
@@ -66927,40 +67336,40 @@ async function statusFood(orderId, opts) {
66927
67336
  }
66928
67337
 
66929
67338
  // src/commands/bounties.ts
66930
- var import_picocolors23 = __toESM(require_picocolors(), 1);
67339
+ var import_picocolors24 = __toESM(require_picocolors(), 1);
66931
67340
  async function withProfile(opts, path6, init2) {
66932
67341
  const requested = opts.profile ?? DEFAULT_PROFILE;
66933
67342
  const resolved = await resolveProfile(requested);
66934
67343
  if (!resolved) {
66935
- process.stderr.write(import_picocolors23.default.red("Not logged in. Run agentgates login first.\n"));
67344
+ process.stderr.write(import_picocolors24.default.red("Not logged in. Run agentgates login first.\n"));
66936
67345
  process.exit(2);
66937
67346
  }
66938
67347
  if (resolved.autoSelected) {
66939
- process.stderr.write(import_picocolors23.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
67348
+ process.stderr.write(import_picocolors24.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
66940
67349
  `));
66941
67350
  }
66942
67351
  const { profile, name: profileName } = resolved;
66943
- const jsonMode3 = opts.json === true;
67352
+ const jsonMode4 = opts.json === true;
66944
67353
  const outcome = await callWithAutoRelogin({
66945
67354
  profile,
66946
67355
  profileName,
66947
- jsonMode: jsonMode3,
66948
- ttyHeader: import_picocolors23.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
67356
+ jsonMode: jsonMode4,
67357
+ ttyHeader: import_picocolors24.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
66949
67358
  fn: (bearer, origin) => apiFetch(path6, init2 ? { bearer, origin, method: init2.method, body: init2.body } : { bearer, origin })
66950
67359
  });
66951
67360
  if (outcome.kind === "auth_failed") {
66952
- if (jsonMode3) {
67361
+ if (jsonMode4) {
66953
67362
  process.stdout.write(JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n");
66954
67363
  process.exit(1);
66955
67364
  }
66956
- process.stderr.write(import_picocolors23.default.red(`\u2715 ${outcome.reason}.
67365
+ process.stderr.write(import_picocolors24.default.red(`\u2715 ${outcome.reason}.
66957
67366
  `));
66958
67367
  process.exit(1);
66959
67368
  }
66960
67369
  if (outcome.kind === "error") {
66961
67370
  const err = outcome.error;
66962
67371
  if (err instanceof ApiError) {
66963
- process.stderr.write(import_picocolors23.default.red(`\u2715 ${err.message} (HTTP ${err.status})
67372
+ process.stderr.write(import_picocolors24.default.red(`\u2715 ${err.message} (HTTP ${err.status})
66964
67373
  `));
66965
67374
  process.exit(1);
66966
67375
  }
@@ -66968,18 +67377,18 @@ async function withProfile(opts, path6, init2) {
66968
67377
  }
66969
67378
  return outcome.result;
66970
67379
  }
66971
- function handleBlocked(res, jsonMode3) {
67380
+ function handleBlocked(res, jsonMode4) {
66972
67381
  if (!res.blocked) return false;
66973
- if (jsonMode3) {
67382
+ if (jsonMode4) {
66974
67383
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
66975
67384
  process.exit(1);
66976
67385
  }
66977
- process.stderr.write(import_picocolors23.default.yellow(`
67386
+ process.stderr.write(import_picocolors24.default.yellow(`
66978
67387
  ${res.reason ?? "Blocked."}
66979
67388
  `));
66980
67389
  if (res.upgrade_url) {
66981
67390
  process.stderr.write(`
66982
- ${import_picocolors23.default.bold(res.upgrade_url)}
67391
+ ${import_picocolors24.default.bold(res.upgrade_url)}
66983
67392
 
66984
67393
  `);
66985
67394
  }
@@ -67022,30 +67431,30 @@ function printTable(rows) {
67022
67431
  const cLeft = w("left", 4);
67023
67432
  const cSubs = w("subs", 4);
67024
67433
  process.stdout.write(
67025
- import_picocolors23.default.dim(
67434
+ import_picocolors24.default.dim(
67026
67435
  "Amount".padStart(cAmount) + " " + "Title".padEnd(cTitle) + " " + "Chain".padEnd(cChain) + " " + "Evidence".padEnd(cEv) + " " + "Left".padStart(cLeft) + " " + "Subs".padStart(cSubs) + " ID"
67027
67436
  ) + "\n"
67028
67437
  );
67029
67438
  for (const c of cells) {
67030
- const title = c.live ? import_picocolors23.default.green(c.title.padEnd(cTitle)) : c.title.padEnd(cTitle);
67439
+ const title = c.live ? import_picocolors24.default.green(c.title.padEnd(cTitle)) : c.title.padEnd(cTitle);
67031
67440
  process.stdout.write(
67032
- import_picocolors23.default.bold(c.amount.padStart(cAmount)) + " " + title + " " + c.chain.padEnd(cChain) + " " + c.ev.padEnd(cEv) + " " + c.left.padStart(cLeft) + " " + c.subs.padStart(cSubs) + " " + import_picocolors23.default.dim(c.id) + "\n"
67441
+ import_picocolors24.default.bold(c.amount.padStart(cAmount)) + " " + title + " " + c.chain.padEnd(cChain) + " " + c.ev.padEnd(cEv) + " " + c.left.padStart(cLeft) + " " + c.subs.padStart(cSubs) + " " + import_picocolors24.default.dim(c.id) + "\n"
67033
67442
  );
67034
67443
  }
67035
67444
  }
67036
67445
  async function listBounties(opts) {
67037
- const jsonMode3 = opts.json === true;
67446
+ const jsonMode4 = opts.json === true;
67038
67447
  const res = await withProfile(opts, "/api/bounties");
67039
- handleBlocked(res, jsonMode3);
67448
+ handleBlocked(res, jsonMode4);
67040
67449
  let rows = res.bounties ?? [];
67041
67450
  const min = opts.min !== void 0 ? Number(opts.min) : void 0;
67042
67451
  const max = opts.max !== void 0 ? Number(opts.max) : void 0;
67043
67452
  if (min !== void 0 && !Number.isFinite(min)) {
67044
- process.stderr.write(import_picocolors23.default.red("\u2715 --min must be a number.\n"));
67453
+ process.stderr.write(import_picocolors24.default.red("\u2715 --min must be a number.\n"));
67045
67454
  process.exit(2);
67046
67455
  }
67047
67456
  if (max !== void 0 && !Number.isFinite(max)) {
67048
- process.stderr.write(import_picocolors23.default.red("\u2715 --max must be a number.\n"));
67457
+ process.stderr.write(import_picocolors24.default.red("\u2715 --max must be a number.\n"));
67049
67458
  process.exit(2);
67050
67459
  }
67051
67460
  rows = rows.filter((r) => {
@@ -67070,22 +67479,22 @@ async function listBounties(opts) {
67070
67479
  });
67071
67480
  const limit = opts.limit !== void 0 ? Number(opts.limit) : 20;
67072
67481
  if (!Number.isFinite(limit) || limit <= 0) {
67073
- process.stderr.write(import_picocolors23.default.red("\u2715 --limit must be a positive number.\n"));
67482
+ process.stderr.write(import_picocolors24.default.red("\u2715 --limit must be a positive number.\n"));
67074
67483
  process.exit(2);
67075
67484
  }
67076
67485
  const shown2 = rows.slice(0, limit);
67077
- if (jsonMode3) {
67486
+ if (jsonMode4) {
67078
67487
  process.stdout.write(JSON.stringify({ bounties: shown2, matched: rows.length }, null, 2) + "\n");
67079
67488
  return;
67080
67489
  }
67081
67490
  if (shown2.length === 0) {
67082
- process.stdout.write(import_picocolors23.default.dim("No active bounties match.\n"));
67491
+ process.stdout.write(import_picocolors24.default.dim("No active bounties match.\n"));
67083
67492
  return;
67084
67493
  }
67085
67494
  printTable(shown2);
67086
67495
  const clipped = rows.length - shown2.length;
67087
67496
  process.stdout.write(
67088
- "\n" + import_picocolors23.default.dim(
67497
+ "\n" + import_picocolors24.default.dim(
67089
67498
  `${shown2.length} of ${rows.length} matching${clipped > 0 ? ` (${clipped} more \u2014 raise --limit)` : ""}. agentgates show <id> for detail.
67090
67499
  `
67091
67500
  )
@@ -67093,58 +67502,58 @@ async function listBounties(opts) {
67093
67502
  process.stdout.write(AI_DIRECTIVE + "\n");
67094
67503
  }
67095
67504
  async function showBounty(id2, opts) {
67096
- const jsonMode3 = opts.json === true;
67505
+ const jsonMode4 = opts.json === true;
67097
67506
  const clean = id2.trim().replace(/^.*\/bounty\//, "").replace(/[?#].*$/, "").trim();
67098
67507
  if (!clean) {
67099
- process.stderr.write(import_picocolors23.default.red("\u2715 Give a bounty id, or a agentgates.ai/bounty/<id> link.\n"));
67508
+ process.stderr.write(import_picocolors24.default.red("\u2715 Give a bounty id, or a agentgates.ai/bounty/<id> link.\n"));
67100
67509
  process.exit(2);
67101
67510
  }
67102
67511
  const res = await withProfile(opts, `/api/bounties/${encodeURIComponent(clean)}`);
67103
- handleBlocked(res, jsonMode3);
67104
- if (jsonMode3) {
67512
+ handleBlocked(res, jsonMode4);
67513
+ if (jsonMode4) {
67105
67514
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
67106
67515
  return;
67107
67516
  }
67108
67517
  const b2 = res.bounty;
67109
67518
  if (!b2) {
67110
- process.stdout.write(import_picocolors23.default.dim("Not found.\n"));
67519
+ process.stdout.write(import_picocolors24.default.dim("Not found.\n"));
67111
67520
  return;
67112
67521
  }
67113
- process.stdout.write("\n" + import_picocolors23.default.bold(b2.title) + "\n\n");
67522
+ process.stdout.write("\n" + import_picocolors24.default.bold(b2.title) + "\n\n");
67114
67523
  process.stdout.write(b2.description + "\n\n");
67115
67524
  process.stdout.write(
67116
- import_picocolors23.default.bold(fmtAmount(b2.amount)) + import_picocolors23.default.dim(" USDC") + import_picocolors23.default.dim(` \xB7 ${chainOf2(b2)} \xB7 ${b2.status.toLowerCase()}`) + (b2.liveNow ? import_picocolors23.default.green(" \xB7 LIVE now") : "") + "\n"
67525
+ import_picocolors24.default.bold(fmtAmount(b2.amount)) + import_picocolors24.default.dim(" USDC") + import_picocolors24.default.dim(` \xB7 ${chainOf2(b2)} \xB7 ${b2.status.toLowerCase()}`) + (b2.liveNow ? import_picocolors24.default.green(" \xB7 LIVE now") : "") + "\n"
67117
67526
  );
67118
67527
  if (b2.claimsAllowed && b2.claimsAllowed > 1) {
67119
67528
  const left = Math.max(0, b2.claimsAllowed - (b2.claimsPaid ?? 0));
67120
67529
  process.stdout.write(
67121
- import_picocolors23.default.dim(
67530
+ import_picocolors24.default.dim(
67122
67531
  `${left} of ${b2.claimsAllowed} claims left` + (b2.perClaimAmount != null ? `, ${fmtAmount(b2.perClaimAmount)} each` : "")
67123
67532
  ) + "\n"
67124
67533
  );
67125
67534
  }
67126
- if (b2.evidenceType) process.stdout.write(import_picocolors23.default.dim(`Evidence required: ${b2.evidenceType}`) + "\n");
67127
- if (b2.expiresAt) process.stdout.write(import_picocolors23.default.dim(`Expires in ${fmtExpiry(b2.expiresAt)}`) + "\n");
67535
+ if (b2.evidenceType) process.stdout.write(import_picocolors24.default.dim(`Evidence required: ${b2.evidenceType}`) + "\n");
67536
+ if (b2.expiresAt) process.stdout.write(import_picocolors24.default.dim(`Expires in ${fmtExpiry(b2.expiresAt)}`) + "\n");
67128
67537
  if (b2.geoLabel && b2.geoScope !== "global") {
67129
- process.stdout.write(import_picocolors23.default.dim(`Creator says: ${b2.geoLabel}`) + "\n");
67538
+ process.stdout.write(import_picocolors24.default.dim(`Creator says: ${b2.geoLabel}`) + "\n");
67130
67539
  }
67131
67540
  if (res.url) process.stdout.write("\n" + res.url + "\n");
67132
67541
  process.stdout.write(AI_DIRECTIVE + "\n");
67133
67542
  }
67134
67543
  async function myBounties(opts) {
67135
- const jsonMode3 = opts.json === true;
67544
+ const jsonMode4 = opts.json === true;
67136
67545
  const res = await withProfile(opts, "/api/bounties?mine=1");
67137
- handleBlocked(res, jsonMode3);
67546
+ handleBlocked(res, jsonMode4);
67138
67547
  const all = res.bounties ?? [];
67139
67548
  const status3 = opts.status?.trim().toUpperCase();
67140
67549
  const rows = status3 ? all.filter((r) => (r.status ?? "").toUpperCase() === status3) : all;
67141
- if (jsonMode3) {
67550
+ if (jsonMode4) {
67142
67551
  process.stdout.write(JSON.stringify({ bounties: rows, submissions: res.submissions ?? [] }, null, 2) + "\n");
67143
67552
  return;
67144
67553
  }
67145
67554
  if (rows.length === 0) {
67146
67555
  process.stdout.write(
67147
- import_picocolors23.default.dim(
67556
+ import_picocolors24.default.dim(
67148
67557
  status3 ? `No bounties of yours are ${status3}.
67149
67558
  ` : "You have not created any bounties yet. `agentgates draft` starts one.\n"
67150
67559
  )
@@ -67154,38 +67563,38 @@ async function myBounties(opts) {
67154
67563
  printTable(rows);
67155
67564
  const subs = res.submissions ?? [];
67156
67565
  if (subs.length > 0) {
67157
- process.stdout.write("\n" + import_picocolors23.default.dim(`Plus ${subs.length} submission(s) on other people's bounties.
67566
+ process.stdout.write("\n" + import_picocolors24.default.dim(`Plus ${subs.length} submission(s) on other people's bounties.
67158
67567
  `));
67159
67568
  }
67160
67569
  process.stdout.write(AI_DIRECTIVE + "\n");
67161
67570
  }
67162
67571
  async function bountyFeed(opts) {
67163
- const jsonMode3 = opts.json === true;
67572
+ const jsonMode4 = opts.json === true;
67164
67573
  const params = new URLSearchParams();
67165
67574
  if (opts.limit) params.set("limit", opts.limit);
67166
67575
  if (opts.type) params.set("type", opts.type);
67167
67576
  const qs = params.toString();
67168
67577
  const res = await withProfile(opts, `/api/bounties/feed${qs ? `?${qs}` : ""}`);
67169
- handleBlocked(res, jsonMode3);
67170
- if (jsonMode3) {
67578
+ handleBlocked(res, jsonMode4);
67579
+ if (jsonMode4) {
67171
67580
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
67172
67581
  return;
67173
67582
  }
67174
67583
  const subs = res.submissions ?? [];
67175
67584
  if (subs.length === 0) {
67176
- process.stdout.write(import_picocolors23.default.dim("Nothing in the feed for that filter.\n"));
67585
+ process.stdout.write(import_picocolors24.default.dim("Nothing in the feed for that filter.\n"));
67177
67586
  return;
67178
67587
  }
67179
67588
  process.stdout.write(
67180
- `${subs.length} submission(s) shown of ${res.total ?? subs.length} total.` + (res.hasMore ? import_picocolors23.default.dim(" More available.") : "") + "\n"
67589
+ `${subs.length} submission(s) shown of ${res.total ?? subs.length} total.` + (res.hasMore ? import_picocolors24.default.dim(" More available.") : "") + "\n"
67181
67590
  );
67182
- process.stdout.write(import_picocolors23.default.dim("Use --json for the full rows.\n"));
67591
+ process.stdout.write(import_picocolors24.default.dim("Use --json for the full rows.\n"));
67183
67592
  }
67184
67593
  async function draftBounty(opts) {
67185
- const jsonMode3 = opts.json === true;
67594
+ const jsonMode4 = opts.json === true;
67186
67595
  const amountNum = Number(opts.amount);
67187
67596
  if (!Number.isFinite(amountNum) || amountNum <= 0) {
67188
- process.stderr.write(import_picocolors23.default.red("\u2715 --amount must be a positive number of USDC.\n"));
67597
+ process.stderr.write(import_picocolors24.default.red("\u2715 --amount must be a positive number of USDC.\n"));
67189
67598
  process.exit(2);
67190
67599
  }
67191
67600
  const res = await withProfile(opts, "/api/bounties", {
@@ -67198,42 +67607,42 @@ async function draftBounty(opts) {
67198
67607
  evidenceType: opts.evidenceType
67199
67608
  }
67200
67609
  });
67201
- handleBlocked(res, jsonMode3);
67202
- if (jsonMode3) {
67610
+ handleBlocked(res, jsonMode4);
67611
+ if (jsonMode4) {
67203
67612
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
67204
67613
  return;
67205
67614
  }
67206
- process.stdout.write("\n" + import_picocolors23.default.green("\u2713") + ` Drafted "${opts.title}" for $${opts.amount} USDC.
67615
+ process.stdout.write("\n" + import_picocolors24.default.green("\u2713") + ` Drafted "${opts.title}" for $${opts.amount} USDC.
67207
67616
 
67208
67617
  `);
67209
- process.stdout.write(import_picocolors23.default.dim("It is a draft. Nobody can see or claim it until you fund the escrow.\n"));
67618
+ process.stdout.write(import_picocolors24.default.dim("It is a draft. Nobody can see or claim it until you fund the escrow.\n"));
67210
67619
  if (res.fund_url) {
67211
- process.stdout.write("\nFund it here:\n" + import_picocolors23.default.bold(res.fund_url) + "\n\n");
67212
- process.stdout.write(import_picocolors23.default.dim("Funding happens in your browser with your own wallet.\n"));
67620
+ process.stdout.write("\nFund it here:\n" + import_picocolors24.default.bold(res.fund_url) + "\n\n");
67621
+ process.stdout.write(import_picocolors24.default.dim("Funding happens in your browser with your own wallet.\n"));
67213
67622
  }
67214
67623
  }
67215
67624
 
67216
67625
  // src/commands/bounty-money.ts
67217
- var import_picocolors24 = __toESM(require_picocolors(), 1);
67626
+ var import_picocolors25 = __toESM(require_picocolors(), 1);
67218
67627
  function failArg6(message) {
67219
- process.stderr.write(import_picocolors24.default.red(`${message}
67628
+ process.stderr.write(import_picocolors25.default.red(`${message}
67220
67629
  `));
67221
67630
  process.exit(2);
67222
67631
  }
67223
- async function loadProfileOrExit(requested, jsonMode3) {
67632
+ async function loadProfileOrExit(requested, jsonMode4) {
67224
67633
  const resolved = await resolveProfile(requested);
67225
67634
  if (!resolved) {
67226
- if (jsonMode3) {
67635
+ if (jsonMode4) {
67227
67636
  process.stdout.write(
67228
67637
  JSON.stringify({ ok: false, status: "auth_failed", error: "Not logged in. Run agentgates login first." }) + "\n"
67229
67638
  );
67230
67639
  } else {
67231
- process.stderr.write(import_picocolors24.default.red("Not logged in. Run agentgates login first.\n"));
67640
+ process.stderr.write(import_picocolors25.default.red("Not logged in. Run agentgates login first.\n"));
67232
67641
  }
67233
67642
  process.exit(2);
67234
67643
  }
67235
- if (resolved.autoSelected && !jsonMode3) {
67236
- process.stderr.write(import_picocolors24.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
67644
+ if (resolved.autoSelected && !jsonMode4) {
67645
+ process.stderr.write(import_picocolors25.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
67237
67646
  `));
67238
67647
  }
67239
67648
  return { profile: resolved.profile, profileName: resolved.name };
@@ -67252,8 +67661,8 @@ function resolveMaxUsd(opts, profile, fallbackHint) {
67252
67661
  );
67253
67662
  }
67254
67663
  async function fundBounty(bountyId, opts) {
67255
- const jsonMode3 = Boolean(opts.json) || !process.stdout.isTTY;
67256
- const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode3);
67664
+ const jsonMode4 = Boolean(opts.json) || !process.stdout.isTTY;
67665
+ const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode4);
67257
67666
  const maxUsd = resolveMaxUsd(opts, profile, "agentgates fund");
67258
67667
  return runIntentFlow({
67259
67668
  endpoint: "/api/intents/propose-fund-bounty",
@@ -67272,17 +67681,17 @@ async function fundBounty(bountyId, opts) {
67272
67681
  },
67273
67682
  profileName,
67274
67683
  initialProfile: profile,
67275
- jsonMode: jsonMode3,
67684
+ jsonMode: jsonMode4,
67276
67685
  shouldOpenBrowser: resolveBrowserDefault(opts.browserMode ?? "auto")
67277
67686
  });
67278
67687
  }
67279
67688
  async function tipBounty(bountyId, amount, opts) {
67280
- const jsonMode3 = Boolean(opts.json) || !process.stdout.isTTY;
67689
+ const jsonMode4 = Boolean(opts.json) || !process.stdout.isTTY;
67281
67690
  const amt = Number(amount);
67282
67691
  if (!Number.isFinite(amt) || amt <= 0) {
67283
67692
  failArg6(`amount must be a positive USDC number (got ${amount}).`);
67284
67693
  }
67285
- const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode3);
67694
+ const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode4);
67286
67695
  const maxUsd = opts.maxUsd !== void 0 ? resolveMaxUsd(opts, profile, "agentgates tip") : Math.ceil(amt * 1.01 * 100) / 100;
67287
67696
  return runIntentFlow({
67288
67697
  endpoint: "/api/intents/propose-tip",
@@ -67302,17 +67711,17 @@ async function tipBounty(bountyId, amount, opts) {
67302
67711
  },
67303
67712
  profileName,
67304
67713
  initialProfile: profile,
67305
- jsonMode: jsonMode3,
67714
+ jsonMode: jsonMode4,
67306
67715
  shouldOpenBrowser: resolveBrowserDefault(opts.browserMode ?? "auto")
67307
67716
  });
67308
67717
  }
67309
67718
  async function subscribeCreator(creatorUserId, opts) {
67310
- const jsonMode3 = Boolean(opts.json) || !process.stdout.isTTY;
67719
+ const jsonMode4 = Boolean(opts.json) || !process.stdout.isTTY;
67311
67720
  const months = opts.months === void 0 ? 1 : Number(opts.months);
67312
67721
  if (![1, 3, 12].includes(months)) {
67313
67722
  failArg6(`--months must be 1, 3 or 12 (got ${opts.months}). Prepaid periods only \u2014 no auto-renew exists.`);
67314
67723
  }
67315
- const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode3);
67724
+ const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode4);
67316
67725
  const maxUsd = resolveMaxUsd(opts, profile, "agentgates subscribe");
67317
67726
  return runIntentFlow({
67318
67727
  endpoint: "/api/intents/propose-subscribe",
@@ -67332,48 +67741,48 @@ async function subscribeCreator(creatorUserId, opts) {
67332
67741
  },
67333
67742
  profileName,
67334
67743
  initialProfile: profile,
67335
- jsonMode: jsonMode3,
67744
+ jsonMode: jsonMode4,
67336
67745
  shouldOpenBrowser: resolveBrowserDefault(opts.browserMode ?? "auto")
67337
67746
  });
67338
67747
  }
67339
67748
 
67340
67749
  // src/commands/bounty-work.ts
67341
- var import_picocolors25 = __toESM(require_picocolors(), 1);
67750
+ var import_picocolors26 = __toESM(require_picocolors(), 1);
67342
67751
  async function runWork(path6, body, opts) {
67343
67752
  const requested = opts.profile ?? DEFAULT_PROFILE;
67344
67753
  const resolved = await resolveProfile(requested);
67345
67754
  if (!resolved) {
67346
- process.stderr.write(import_picocolors25.default.red("Not logged in. Run agentgates login first.\n"));
67755
+ process.stderr.write(import_picocolors26.default.red("Not logged in. Run agentgates login first.\n"));
67347
67756
  process.exit(2);
67348
67757
  }
67349
67758
  if (resolved.autoSelected) {
67350
- process.stderr.write(import_picocolors25.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
67759
+ process.stderr.write(import_picocolors26.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
67351
67760
  `));
67352
67761
  }
67353
- const jsonMode3 = opts.json === true;
67762
+ const jsonMode4 = opts.json === true;
67354
67763
  const outcome = await callWithAutoRelogin({
67355
67764
  profile: resolved.profile,
67356
67765
  profileName: resolved.name,
67357
- jsonMode: jsonMode3,
67358
- ttyHeader: import_picocolors25.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
67766
+ jsonMode: jsonMode4,
67767
+ ttyHeader: import_picocolors26.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
67359
67768
  fn: (bearer, origin) => apiFetch(path6, { bearer, origin, method: "POST", body })
67360
67769
  });
67361
67770
  if (outcome.kind === "auth_failed") {
67362
- if (jsonMode3) {
67771
+ if (jsonMode4) {
67363
67772
  process.stdout.write(JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n");
67364
67773
  process.exit(1);
67365
67774
  }
67366
- process.stderr.write(import_picocolors25.default.red(`\u2715 ${outcome.reason}.
67775
+ process.stderr.write(import_picocolors26.default.red(`\u2715 ${outcome.reason}.
67367
67776
  `));
67368
67777
  process.exit(1);
67369
67778
  }
67370
67779
  if (outcome.kind === "error") {
67371
67780
  const err = outcome.error;
67372
67781
  if (err instanceof ApiError) {
67373
- if (jsonMode3) {
67782
+ if (jsonMode4) {
67374
67783
  process.stdout.write(JSON.stringify({ ok: false, error: err.message, http_status: err.status }) + "\n");
67375
67784
  } else {
67376
- process.stderr.write(import_picocolors25.default.red(`\u2715 ${err.message} (HTTP ${err.status})
67785
+ process.stderr.write(import_picocolors26.default.red(`\u2715 ${err.message} (HTTP ${err.status})
67377
67786
  `));
67378
67787
  }
67379
67788
  process.exit(1);
@@ -67382,29 +67791,29 @@ async function runWork(path6, body, opts) {
67382
67791
  }
67383
67792
  const data4 = outcome.result;
67384
67793
  if (data4.blocked) {
67385
- if (jsonMode3) {
67794
+ if (jsonMode4) {
67386
67795
  process.stdout.write(JSON.stringify({ ok: false, ...data4 }) + "\n");
67387
67796
  process.exit(1);
67388
67797
  }
67389
- process.stderr.write(import_picocolors25.default.yellow(`
67798
+ process.stderr.write(import_picocolors26.default.yellow(`
67390
67799
  ${data4.reason ?? "Blocked."}
67391
67800
  `));
67392
67801
  if (data4.upgrade_url) process.stderr.write(`
67393
- ${import_picocolors25.default.bold(data4.upgrade_url)}
67802
+ ${import_picocolors26.default.bold(data4.upgrade_url)}
67394
67803
 
67395
67804
  `);
67396
67805
  process.exit(1);
67397
67806
  }
67398
67807
  if (typeof data4.error === "string" && data4.error) {
67399
- if (jsonMode3) {
67808
+ if (jsonMode4) {
67400
67809
  process.stdout.write(JSON.stringify({ ok: false, error: data4.error }) + "\n");
67401
67810
  } else {
67402
- process.stderr.write(import_picocolors25.default.red(`\u2715 ${data4.error}
67811
+ process.stderr.write(import_picocolors26.default.red(`\u2715 ${data4.error}
67403
67812
  `));
67404
67813
  }
67405
67814
  process.exit(1);
67406
67815
  }
67407
- if (jsonMode3) {
67816
+ if (jsonMode4) {
67408
67817
  process.stdout.write(JSON.stringify({ ok: true, ...data4 }) + "\n");
67409
67818
  return;
67410
67819
  }
@@ -67442,28 +67851,28 @@ async function bountyRetention(bountyId, opts) {
67442
67851
  }
67443
67852
 
67444
67853
  // src/commands/bounty-deliver.ts
67445
- var import_picocolors26 = __toESM(require_picocolors(), 1);
67854
+ var import_picocolors27 = __toESM(require_picocolors(), 1);
67446
67855
  import { spawn } from "node:child_process";
67447
67856
  var FLUSH_MS = 400;
67448
67857
  var FLUSH_BYTES = 2048;
67449
67858
  async function deliver(bountyId, command, opts) {
67450
- const jsonMode3 = opts.json === true;
67859
+ const jsonMode4 = opts.json === true;
67451
67860
  const requested = opts.profile ?? DEFAULT_PROFILE;
67452
67861
  const resolved = await resolveProfile(requested);
67453
67862
  if (!resolved) {
67454
- process.stderr.write(import_picocolors26.default.red("Not logged in. Run agentgates login first.\n"));
67863
+ process.stderr.write(import_picocolors27.default.red("Not logged in. Run agentgates login first.\n"));
67455
67864
  process.exit(2);
67456
67865
  }
67457
- if (resolved.autoSelected && !jsonMode3) {
67458
- process.stderr.write(import_picocolors26.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
67866
+ if (resolved.autoSelected && !jsonMode4) {
67867
+ process.stderr.write(import_picocolors27.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
67459
67868
  `));
67460
67869
  }
67461
67870
  const post = async (path6, body) => {
67462
67871
  const outcome = await callWithAutoRelogin({
67463
67872
  profile: resolved.profile,
67464
67873
  profileName: resolved.name,
67465
- jsonMode: jsonMode3,
67466
- ttyHeader: import_picocolors26.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
67874
+ jsonMode: jsonMode4,
67875
+ ttyHeader: import_picocolors27.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
67467
67876
  fn: (bearer, origin) => apiFetch(path6, { bearer, origin, method: "POST", body })
67468
67877
  });
67469
67878
  if (outcome.kind === "auth_failed") throw new Error(outcome.reason);
@@ -67471,14 +67880,14 @@ async function deliver(bountyId, command, opts) {
67471
67880
  return outcome.result;
67472
67881
  };
67473
67882
  const die = (msg, data4) => {
67474
- if (jsonMode3) {
67883
+ if (jsonMode4) {
67475
67884
  process.stdout.write(JSON.stringify({ ok: false, error: msg, ...data4 ?? {} }) + "\n");
67476
67885
  } else {
67477
- process.stderr.write(import_picocolors26.default.red(`
67886
+ process.stderr.write(import_picocolors27.default.red(`
67478
67887
  \u2715 ${msg}
67479
67888
  `));
67480
67889
  if (data4?.upgrade_url) process.stderr.write(`
67481
- ${import_picocolors26.default.bold(data4.upgrade_url)}
67890
+ ${import_picocolors27.default.bold(data4.upgrade_url)}
67482
67891
 
67483
67892
  `);
67484
67893
  }
@@ -67501,9 +67910,9 @@ ${import_picocolors26.default.bold(data4.upgrade_url)}
67501
67910
  if (started.error) return void die(started.error, started);
67502
67911
  const runId = started.run_id;
67503
67912
  if (!runId) return void die("The service opened a run but did not name it.");
67504
- if (!jsonMode3) {
67913
+ if (!jsonMode4) {
67505
67914
  process.stderr.write(
67506
- import_picocolors26.default.bold("\n\u25CF LIVE ") + import_picocolors26.default.dim("everything below is going onto the bounty page as it happens\n") + import_picocolors26.default.dim(` ${started.url ?? ""}
67915
+ import_picocolors27.default.bold("\n\u25CF LIVE ") + import_picocolors27.default.dim("everything below is going onto the bounty page as it happens\n") + import_picocolors27.default.dim(` ${started.url ?? ""}
67507
67916
 
67508
67917
  `)
67509
67918
  );
@@ -67532,7 +67941,7 @@ ${import_picocolors26.default.bold(data4.upgrade_url)}
67532
67941
  const timer = setInterval(() => flush(true), FLUSH_MS);
67533
67942
  const consume = (data4) => {
67534
67943
  buffer += data4;
67535
- if (!opts.quiet && !jsonMode3) process.stderr.write(data4);
67944
+ if (!opts.quiet && !jsonMode4) process.stderr.write(data4);
67536
67945
  flush();
67537
67946
  };
67538
67947
  let exitCode = 0;
@@ -67555,10 +67964,10 @@ ${import_picocolors26.default.bold(data4.upgrade_url)}
67555
67964
  child.stdout.on("data", (d) => consume(d));
67556
67965
  child.stderr.setEncoding("utf8");
67557
67966
  child.stderr.on("data", (d) => {
67558
- if (!jsonMode3) process.stderr.write(import_picocolors26.default.dim(d));
67967
+ if (!jsonMode4) process.stderr.write(import_picocolors27.default.dim(d));
67559
67968
  });
67560
67969
  child.on("error", (err) => {
67561
- process.stderr.write(import_picocolors26.default.red(`
67970
+ process.stderr.write(import_picocolors27.default.red(`
67562
67971
  \u2715 Could not run ${command[0]}: ${err.message}
67563
67972
  `));
67564
67973
  resolve2(127);
@@ -67580,7 +67989,7 @@ ${import_picocolors26.default.bold(data4.upgrade_url)}
67580
67989
  }
67581
67990
  if (finished.blocked) return void die(finished.reason ?? "Blocked.", finished);
67582
67991
  if (finished.error) return void die(finished.error, finished);
67583
- if (jsonMode3) {
67992
+ if (jsonMode4) {
67584
67993
  process.stdout.write(
67585
67994
  JSON.stringify({
67586
67995
  ok: true,
@@ -67595,14 +68004,14 @@ ${import_picocolors26.default.bold(data4.upgrade_url)}
67595
68004
  }
67596
68005
  if (appendFailure) {
67597
68006
  process.stderr.write(
67598
- import_picocolors26.default.yellow(`
68007
+ import_picocolors27.default.yellow(`
67599
68008
  ! Some output did not reach the page: ${appendFailure}
67600
- `) + import_picocolors26.default.yellow(" What did arrive is sealed below. Check it before you submit.\n")
68009
+ `) + import_picocolors27.default.yellow(" What did arrive is sealed below. Check it before you submit.\n")
67601
68010
  );
67602
68011
  }
67603
68012
  if (exitCode) {
67604
68013
  process.stderr.write(
67605
- import_picocolors26.default.yellow(`
68014
+ import_picocolors27.default.yellow(`
67606
68015
  ! ${command[0]} exited ${exitCode}. The run was sealed with what it produced.
67607
68016
  `)
67608
68017
  );
@@ -67612,7 +68021,7 @@ ${import_picocolors26.default.bold(data4.upgrade_url)}
67612
68021
  }
67613
68022
 
67614
68023
  // src/commands/trade.ts
67615
- var import_picocolors27 = __toESM(require_picocolors(), 1);
68024
+ var import_picocolors28 = __toESM(require_picocolors(), 1);
67616
68025
 
67617
68026
  // src/lib/trade-sol.ts
67618
68027
  var import_web3 = __toESM(require_index_cjs(), 1);
@@ -67974,11 +68383,11 @@ async function runTrade(args) {
67974
68383
  }
67975
68384
 
67976
68385
  // src/commands/trade.ts
67977
- function fail(message, json) {
67978
- if (json) {
68386
+ function fail(message, json2) {
68387
+ if (json2) {
67979
68388
  process.stdout.write(JSON.stringify({ ok: false, error: message }) + "\n");
67980
68389
  } else {
67981
- process.stderr.write(import_picocolors27.default.red(`\u2715 ${message}
68390
+ process.stderr.write(import_picocolors28.default.red(`\u2715 ${message}
67982
68391
  `));
67983
68392
  }
67984
68393
  process.exit(1);
@@ -68169,7 +68578,7 @@ async function tradeBuy(coinArg, amount, opts) {
68169
68578
  }
68170
68579
  const { keypair, state, created } = await loadOrCreateTradeKey();
68171
68580
  if (created && !opts.json) {
68172
- process.stderr.write(import_picocolors27.default.dim(`Generated the agent trading key ${state.address} (${tradeKeyPath()}).
68581
+ process.stderr.write(import_picocolors28.default.dim(`Generated the agent trading key ${state.address} (${tradeKeyPath()}).
68173
68582
  `));
68174
68583
  }
68175
68584
  const result = await runTrade({ ctx: ctx2, keypair, token: coin.mint, side: "buy", amount, minOut: opts.minOut });
@@ -68223,7 +68632,7 @@ async function tradeOrderPlace(coinArg, opts) {
68223
68632
  if (opts.mcap && !opts.at) fail("--mcap qualifies --at.", opts.json);
68224
68633
  const { keypair, state, created } = await loadOrCreateTradeKey();
68225
68634
  if (created && !opts.json) {
68226
- process.stderr.write(import_picocolors27.default.dim(`Generated the agent trading key ${state.address} (${tradeKeyPath()}).
68635
+ process.stderr.write(import_picocolors28.default.dim(`Generated the agent trading key ${state.address} (${tradeKeyPath()}).
68227
68636
  `));
68228
68637
  }
68229
68638
  let amount;
@@ -68388,7 +68797,7 @@ async function tradePositions(opts) {
68388
68797
  }
68389
68798
 
68390
68799
  // src/commands/desk.ts
68391
- var import_picocolors28 = __toESM(require_picocolors(), 1);
68800
+ var import_picocolors29 = __toESM(require_picocolors(), 1);
68392
68801
 
68393
68802
  // src/lib/desk-sol.ts
68394
68803
  var import_web32 = __toESM(require_index_cjs(), 1);
@@ -68558,11 +68967,11 @@ async function runDeskTrade(args) {
68558
68967
  }
68559
68968
 
68560
68969
  // src/commands/desk.ts
68561
- function fail2(message, json) {
68562
- if (json) {
68970
+ function fail2(message, json2) {
68971
+ if (json2) {
68563
68972
  process.stdout.write(JSON.stringify({ ok: false, error: message }) + "\n");
68564
68973
  } else {
68565
- process.stderr.write(import_picocolors28.default.red(`\u2715 ${message}
68974
+ process.stderr.write(import_picocolors29.default.red(`\u2715 ${message}
68566
68975
  `));
68567
68976
  }
68568
68977
  process.exit(1);
@@ -68705,7 +69114,7 @@ async function deskDeposit(amount, opts) {
68705
69114
  if (units <= 0n) fail2("Deposit amount must be above zero.", opts.json);
68706
69115
  const { keypair, state, created } = await loadOrCreateTradeKey();
68707
69116
  if (created && !opts.json) {
68708
- process.stderr.write(import_picocolors28.default.dim(`Generated the agent trading key ${state.address} (${tradeKeyPath()}).
69117
+ process.stderr.write(import_picocolors29.default.dim(`Generated the agent trading key ${state.address} (${tradeKeyPath()}).
68709
69118
  `));
68710
69119
  }
68711
69120
  const result = await runDeskCeremony({
@@ -68800,13 +69209,13 @@ async function deskSessionRegister(opts) {
68800
69209
  }
68801
69210
  const owner = await loadOrCreateTradeKey();
68802
69211
  if (owner.created && !opts.json) {
68803
- process.stderr.write(import_picocolors28.default.dim(`Generated the agent trading key ${owner.state.address} (${tradeKeyPath()}).
69212
+ process.stderr.write(import_picocolors29.default.dim(`Generated the agent trading key ${owner.state.address} (${tradeKeyPath()}).
68804
69213
  `));
68805
69214
  }
68806
69215
  const session = await loadOrCreateDeskSessionKey();
68807
69216
  if (session.created && !opts.json) {
68808
69217
  process.stderr.write(
68809
- import_picocolors28.default.dim(`Generated the desk session key ${session.state.address} (${deskSessionKeyPath()}).
69218
+ import_picocolors29.default.dim(`Generated the desk session key ${session.state.address} (${deskSessionKeyPath()}).
68810
69219
  `)
68811
69220
  );
68812
69221
  }
@@ -69348,7 +69757,7 @@ program2.command("fund").description(
69348
69757
  }
69349
69758
  if (opts.usdc || opts.gas || opts.chain) {
69350
69759
  process.stderr.write(
69351
- import_picocolors29.default.red(
69760
+ import_picocolors30.default.red(
69352
69761
  `\u2715 --usdc/--gas/--chain go with an ADDRESS target (0x\u2026 or Solana base58); "${target}" reads as a bounty id.
69353
69762
  `
69354
69763
  )
@@ -69502,14 +69911,14 @@ email.command("send").description("Send from an inbox (needs the wallet's signat
69502
69911
  await emailSend();
69503
69912
  });
69504
69913
  var passwords = program2.command("passwords").description(
69505
- "Logins your agent stores and uses without ever seeing one. It mints its own key, seals each login on this machine and logs in through an attested confidential VM; no browser, no account, no human. `invite` hands a person the owner seat."
69914
+ "Logins your agent stores and uses without ever seeing one. It mints its own key, seals each login on this machine and logs in through an attested confidential VM; no browser, no account, no human. `invite` hands these logins to a person."
69506
69915
  );
69507
69916
  passwords.command("pricing").description("The free tier, the plans (passwords held, uses a day) and the per-use meter. Public read: no key, no account, no payment.").option("--json", "machine-readable output (the passwords slice of the identity catalog)").action(async (opts) => {
69508
69917
  await passwordsPricing(opts);
69509
69918
  });
69510
69919
  passwords.command("init").description(
69511
- "Mint two twelve-word phrases and their keys, or bring them: the signing words are this account on agentgates.ai, the vault words open what it stores. Both print once, at the mint. A second run prints the address and changes nothing. AGENTGATES_PASSWORDS_SEED (with AGENTGATES_PASSWORDS_VAULT_SEED beside it) is the key for every command with no file at all."
69512
- ).option("--seed <twelve words>", "bring the signing phrase (quote it)").option("--vault-seed <twelve words>", "bring the vault phrase (quote it); alone, it adds a lock to the signing key already here").option("--reveal-seed", "print this key's words again").option("--import <hex>", "bring a bare 32-byte secp256k1 private key (64 hex chars) instead of words").option("--replace", "with --seed, --vault-seed or --import: overwrite what is already here (the old keys are the only things that open the rows they sealed)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
69920
+ "Mint twelve words and their key, or bring them: the words are this account on agentgates.ai. The key signs every call and locks what it stores. They print once, at the mint. A second run prints the address and changes nothing. AGENTGATES_PASSWORDS_SEED is the key for every command with no file at all."
69921
+ ).option("--seed <twelve words>", "bring the phrase (quote it)").option("--reveal-seed", "print this key's words again").option("--import <hex>", "bring a bare 32-byte secp256k1 private key (64 hex chars) instead of words").option("--replace", "with --seed or --import: overwrite what is already here (the old key is the only thing that opens the rows it sealed)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
69513
69922
  await passwordsInit(opts);
69514
69923
  });
69515
69924
  passwords.command("add").alias("store").description("Store a login: sealed on this machine to this key's own signature and to the box's published key, then posted. The server holds ciphertext it cannot open. Free at every tier.").requiredOption("--label <name>", "what to call it (48 chars)").option("--host <hostname>", "a site it may be used on, repeatable (1 to 8; app.example.com, no wildcards)", (v, prev) => [...prev, v], []).option("--hosts <a,b>", "the same, comma separated").option("--username <u>", "login rows only; an email address is not a secret").option("--password <p>", "the password (visible to ps for the length of the call; --password-stdin avoids that)").option("--password-stdin", "read the password from stdin instead").option("--kind <kind>", "login | api_key | totp | raw (default login)").option("--totp-seed <base32>", "the authenticator seed (login rows may carry one beside the password; totp rows need it)").option("--api-key <value>", "api_key rows").option("--raw <value>", "raw rows").option("--notes <text>", "owner-only, sealed").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
@@ -69526,7 +69935,7 @@ passwords.command("list").description("The rows this key holds, and the rows ano
69526
69935
  await passwordsList(opts);
69527
69936
  });
69528
69937
  passwords.command("invite").description(
69529
- "Onboard a human: print a link they open to take the owner seat over this key's logins and set the guardrails (their wallet, their vault lock, which uses, ask-me). The link is the key to those logins until it is used, withdrawn or expires. Once accepted, this key uses them under their permit."
69938
+ "Invite a person: print a link they open to take this key's logins under their own wallet and set the guardrails (which uses, ask-me). The link is the key to those logins until it is used, withdrawn or expires. Once accepted, this key uses them under their permit."
69530
69939
  ).option("--rows <id,id>", "hand over these rows only (default: every row this key holds)").option("--minutes <n>", "how long the link works, 5 to 60 (default 15)").option("--uses <login,totp,header>", "the uses to propose on the permit (default all three)").option("--days <n>", "the permit length to propose, 1 to 366 (default 30)").option("--no-ask-me", "propose the permit without the ask-me switch (the person can still turn it on)").option("--withdraw <link>", "kill a link you already printed").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts, command) => {
69531
69940
  const askSource = command.getOptionValueSource("askMe");
69532
69941
  await passwordsInvite({ ...opts, noAskMe: askSource === "cli" && opts.askMe === false });
@@ -69546,11 +69955,29 @@ browser.command("tasks").description("The tasks this key owns, newest first.").o
69546
69955
  browser.command("task <id>").description("One task with its answer and the transcript of what it did.").option("--wait [seconds]", "wait until it settles (15 minutes by default)").option("--cancel", "cancel it while it is still queued; the reservation is released").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (id2, opts) => {
69547
69956
  await browserTask(id2, opts);
69548
69957
  });
69958
+ program2.command("init").description(
69959
+ "Mint twelve words and their key, or bring them: the words are this account on agentgates.ai. They sign every call, hold the balance and lock the vault. Printed once, at the mint, with what to tell your human. AGENTGATES_PASSWORDS_SEED is the key for every command with no file at all."
69960
+ ).option("--seed <twelve words>", "bring the phrase (quote it)").option("--reveal-seed", "print this key's words again, with the handoff for your human").option("--import <hex>", "bring a bare 32-byte secp256k1 private key (64 hex chars) instead of words").option("--replace", "with --seed or --import: overwrite what is already here").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
69961
+ await passwordsInit(opts);
69962
+ });
69963
+ program2.command("open").description(
69964
+ "Hand this session to a human: opens agentgates.ai in the browser already logged in as this key's account. The words travel once over 127.0.0.1 with a one-time token; never a server, never a URL, never a page that stays."
69965
+ ).option("--wait <seconds>", "how long the link stays alive (300)").option("--no-browser", "print the link instead of opening it").option("--print-url", "print the link as well as opening it").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
69966
+ await sessionOpen(opts);
69967
+ });
69968
+ program2.command("receive").description(
69969
+ "Take a session from a human: prints a code; on agentgates.ai the human presses Top up \u2192 Hand this session to my agent and types it. The words arrive once over 127.0.0.1 and this CLI becomes that account."
69970
+ ).option("--wait <seconds>", "how long the code stays alive (300)").option("--replace", "overwrite the key already here (the old key is the only thing that opens the rows it sealed)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
69971
+ await sessionReceive(opts);
69972
+ });
69973
+ browser.command("balance").description("The prepaid balance every step draws from, and this key's own deposit address to top it up (USDC on Base or Polygon).").option("--scan", "ask the lane to credit a fresh arrival now instead of within five minutes").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
69974
+ await browserBalance(opts);
69975
+ });
69549
69976
  program2.parseAsync(process.argv).catch((err) => {
69550
- process.stderr.write(import_picocolors29.default.red(`\u2715 ${err.message}
69977
+ process.stderr.write(import_picocolors30.default.red(`\u2715 ${err.message}
69551
69978
  `));
69552
69979
  if (process.env.BOUNTY_DEBUG) {
69553
- process.stderr.write(import_picocolors29.default.dim((err.stack ?? "") + "\n"));
69980
+ process.stderr.write(import_picocolors30.default.dim((err.stack ?? "") + "\n"));
69554
69981
  }
69555
69982
  process.exit(1);
69556
69983
  });