@agentgates/cli 0.84.0 → 0.85.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.mjs +205 -46
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -3041,6 +3041,41 @@ var require_commander = __commonJS({
3041
3041
  }
3042
3042
  });
3043
3043
 
3044
+ // src/lib/terminal-text.ts
3045
+ function scrubText(text) {
3046
+ return text.replace(UNSAFE, "");
3047
+ }
3048
+ function scrubDeep(value) {
3049
+ if (typeof value === "string") return scrubText(value);
3050
+ if (Array.isArray(value)) return value.map((v) => scrubDeep(v));
3051
+ if (value && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype) {
3052
+ const out = {};
3053
+ for (const [k, v] of Object.entries(value)) out[scrubText(k)] = scrubDeep(v);
3054
+ return out;
3055
+ }
3056
+ return value;
3057
+ }
3058
+ function installServerTextScrub() {
3059
+ if (installed || typeof Response === "undefined") return;
3060
+ installed = true;
3061
+ const json2 = Response.prototype.json;
3062
+ Object.defineProperty(Response.prototype, "json", {
3063
+ configurable: true,
3064
+ writable: true,
3065
+ value: async function scrubbedJson() {
3066
+ return scrubDeep(await json2.call(this));
3067
+ }
3068
+ });
3069
+ }
3070
+ var UNSAFE, installed;
3071
+ var init_terminal_text = __esm({
3072
+ "src/lib/terminal-text.ts"() {
3073
+ "use strict";
3074
+ UNSAFE = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]/g;
3075
+ installed = false;
3076
+ }
3077
+ });
3078
+
3044
3079
  // node_modules/picocolors/picocolors.js
3045
3080
  var require_picocolors = __commonJS({
3046
3081
  "node_modules/picocolors/picocolors.js"(exports, module) {
@@ -3128,7 +3163,7 @@ var init_constants = __esm({
3128
3163
  trim = (v) => v ? v.replace(/\/$/, "") : "";
3129
3164
  CLI_API_ORIGIN = trim(process.env.BOUNTY_API_ORIGIN) || "https://cli.agentgates.ai";
3130
3165
  CREATORS_ORIGIN = trim(process.env.BOUNTY_CREATORS_ORIGIN) || "https://agentgates.ai";
3131
- CLI_VERSION = "0.84.0";
3166
+ CLI_VERSION = "0.85.0";
3132
3167
  CLI_USER_AGENT = `agentgates-cli/${CLI_VERSION}`;
3133
3168
  AI_DIRECTIVE = "\n[AI: present the above verbatim inside a markdown code block. Do not reformat, summarize, or omit rows.]";
3134
3169
  }
@@ -32479,7 +32514,7 @@ async function signedFetch(wallet, method, path8, body, timeoutMs = 13e4) {
32479
32514
  const text = await res.text();
32480
32515
  let json2 = null;
32481
32516
  try {
32482
- json2 = text ? JSON.parse(text) : null;
32517
+ json2 = text ? scrubDeep(JSON.parse(text)) : null;
32483
32518
  } catch {
32484
32519
  json2 = null;
32485
32520
  }
@@ -32658,6 +32693,7 @@ var init_passwords_wire = __esm({
32658
32693
  init_passwords_seal();
32659
32694
  init_tdx_attestation();
32660
32695
  init_cvm_approved();
32696
+ init_terminal_text();
32661
32697
  trim2 = (v) => v ? v.replace(/\/$/, "") : "";
32662
32698
  ACCOUNT_HEADS = { credits: "account/balance", deposit: "account/deposit", plans: "account/plans", keys: "account/keys", docs: "account/docs", catalog: "account/catalog", notify: "account/notify", founder: "account/founder", renew: "account/renew", "seal-key": "account/seal-key", "seal-grants": "account/seal-grants" };
32663
32699
  SERVICE_HEADS = /* @__PURE__ */ new Set(["booth", "booths", "browser", "passwords", "phones", "inboxes", "calls", "personas", "playbooks", "intents", "memory", "ag", "integrations", "sites"]);
@@ -46952,7 +46988,7 @@ var require_lib3 = __commonJS({
46952
46988
  }
46953
46989
  var INTERNALS$1 = /* @__PURE__ */ Symbol("Response internals");
46954
46990
  var STATUS_CODES = http2.STATUS_CODES;
46955
- var Response = class _Response {
46991
+ var Response2 = class _Response {
46956
46992
  constructor() {
46957
46993
  let body = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null;
46958
46994
  let opts = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
@@ -47010,8 +47046,8 @@ var require_lib3 = __commonJS({
47010
47046
  });
47011
47047
  }
47012
47048
  };
47013
- Body.mixIn(Response.prototype);
47014
- Object.defineProperties(Response.prototype, {
47049
+ Body.mixIn(Response2.prototype);
47050
+ Object.defineProperties(Response2.prototype, {
47015
47051
  url: { enumerable: true },
47016
47052
  status: { enumerable: true },
47017
47053
  ok: { enumerable: true },
@@ -47020,7 +47056,7 @@ var require_lib3 = __commonJS({
47020
47056
  headers: { enumerable: true },
47021
47057
  clone: { enumerable: true }
47022
47058
  });
47023
- Object.defineProperty(Response.prototype, Symbol.toStringTag, {
47059
+ Object.defineProperty(Response2.prototype, Symbol.toStringTag, {
47024
47060
  value: "Response",
47025
47061
  writable: false,
47026
47062
  enumerable: false,
@@ -47354,7 +47390,7 @@ var require_lib3 = __commonJS({
47354
47390
  };
47355
47391
  const codings = headers.get("Content-Encoding");
47356
47392
  if (!request.compress || request.method === "HEAD" || codings === null || res.statusCode === 204 || res.statusCode === 304) {
47357
- response = new Response(body, response_options);
47393
+ response = new Response2(body, response_options);
47358
47394
  resolve3(response);
47359
47395
  return;
47360
47396
  }
@@ -47364,7 +47400,7 @@ var require_lib3 = __commonJS({
47364
47400
  };
47365
47401
  if (codings == "gzip" || codings == "x-gzip") {
47366
47402
  body = body.pipe(zlib.createGunzip(zlibOptions));
47367
- response = new Response(body, response_options);
47403
+ response = new Response2(body, response_options);
47368
47404
  resolve3(response);
47369
47405
  return;
47370
47406
  }
@@ -47376,12 +47412,12 @@ var require_lib3 = __commonJS({
47376
47412
  } else {
47377
47413
  body = body.pipe(zlib.createInflateRaw());
47378
47414
  }
47379
- response = new Response(body, response_options);
47415
+ response = new Response2(body, response_options);
47380
47416
  resolve3(response);
47381
47417
  });
47382
47418
  raw.on("end", function() {
47383
47419
  if (!response) {
47384
- response = new Response(body, response_options);
47420
+ response = new Response2(body, response_options);
47385
47421
  resolve3(response);
47386
47422
  }
47387
47423
  });
@@ -47389,11 +47425,11 @@ var require_lib3 = __commonJS({
47389
47425
  }
47390
47426
  if (codings == "br" && typeof zlib.createBrotliDecompress === "function") {
47391
47427
  body = body.pipe(zlib.createBrotliDecompress());
47392
- response = new Response(body, response_options);
47428
+ response = new Response2(body, response_options);
47393
47429
  resolve3(response);
47394
47430
  return;
47395
47431
  }
47396
- response = new Response(body, response_options);
47432
+ response = new Response2(body, response_options);
47397
47433
  resolve3(response);
47398
47434
  });
47399
47435
  writeToStream(req, request);
@@ -47435,7 +47471,7 @@ var require_lib3 = __commonJS({
47435
47471
  exports.default = exports;
47436
47472
  exports.Headers = Headers;
47437
47473
  exports.Request = Request;
47438
- exports.Response = Response;
47474
+ exports.Response = Response2;
47439
47475
  exports.FetchError = FetchError;
47440
47476
  exports.AbortError = AbortError;
47441
47477
  }
@@ -63625,6 +63661,7 @@ var {
63625
63661
  } = import_index.default;
63626
63662
 
63627
63663
  // src/main.ts
63664
+ init_terminal_text();
63628
63665
  var import_picocolors39 = __toESM(require_picocolors(), 1);
63629
63666
 
63630
63667
  // src/commands/login.ts
@@ -63632,6 +63669,7 @@ var import_picocolors2 = __toESM(require_picocolors(), 1);
63632
63669
 
63633
63670
  // src/lib/api.ts
63634
63671
  init_constants();
63672
+ init_terminal_text();
63635
63673
  var ApiError = class extends Error {
63636
63674
  constructor(status4, code, message, body) {
63637
63675
  super(message);
@@ -63680,7 +63718,7 @@ async function apiFetch(pathname, opts = {}) {
63680
63718
  let parsed = null;
63681
63719
  if (text) {
63682
63720
  try {
63683
- parsed = JSON.parse(text);
63721
+ parsed = scrubDeep(JSON.parse(text));
63684
63722
  } catch {
63685
63723
  }
63686
63724
  }
@@ -64292,6 +64330,7 @@ init_constants();
64292
64330
 
64293
64331
  // src/lib/sse-client.ts
64294
64332
  init_constants();
64333
+ init_terminal_text();
64295
64334
  async function* streamSse(url, opts = {}) {
64296
64335
  const headers = {
64297
64336
  accept: "text/event-stream",
@@ -64323,7 +64362,7 @@ async function* streamSse(url, opts = {}) {
64323
64362
  let parsed = null;
64324
64363
  if (text) {
64325
64364
  try {
64326
- parsed = JSON.parse(text);
64365
+ parsed = scrubDeep(JSON.parse(text));
64327
64366
  } catch {
64328
64367
  }
64329
64368
  }
@@ -64357,7 +64396,7 @@ async function* streamSse(url, opts = {}) {
64357
64396
  const payload = dataLines.join("\n");
64358
64397
  dataLines = [];
64359
64398
  try {
64360
- yield JSON.parse(payload);
64399
+ yield scrubDeep(JSON.parse(payload));
64361
64400
  } catch {
64362
64401
  }
64363
64402
  }
@@ -64602,7 +64641,7 @@ function shortAddress(addr) {
64602
64641
 
64603
64642
  // src/commands/onboard.ts
64604
64643
  var import_picocolors12 = __toESM(require_picocolors(), 1);
64605
- import { createInterface as createInterface2 } from "node:readline/promises";
64644
+ import { createInterface as createInterface4 } from "node:readline/promises";
64606
64645
  init_constants();
64607
64646
 
64608
64647
  // src/lib/water.ts
@@ -64925,10 +64964,11 @@ async function requirePasswordsKey() {
64925
64964
  // src/lib/x402-pay.ts
64926
64965
  init_lib2();
64927
64966
  var EVM_CHAINS = {
64928
- base: { chainId: 8453, rpcs: ["https://mainnet.base.org", "https://base.drpc.org"] },
64929
- polygon: { chainId: 137, rpcs: ["https://polygon.drpc.org", "https://1rpc.io/matic"] },
64930
- arbitrum: { chainId: 42161, rpcs: ["https://arb1.arbitrum.io/rpc", "https://arbitrum.drpc.org"] }
64967
+ base: { chainId: 8453, usdc: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", rpcs: ["https://mainnet.base.org", "https://base.drpc.org"] },
64968
+ polygon: { chainId: 137, usdc: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359", rpcs: ["https://polygon.drpc.org", "https://1rpc.io/matic"] },
64969
+ arbitrum: { chainId: 42161, usdc: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", rpcs: ["https://arb1.arbitrum.io/rpc", "https://arbitrum.drpc.org"] }
64931
64970
  };
64971
+ var MAX_PAYMENT_WINDOW_SECONDS = 900;
64932
64972
  function evmLegs(body) {
64933
64973
  const out = [];
64934
64974
  for (const leg of body.accepts ?? []) {
@@ -64937,6 +64977,7 @@ function evmLegs(body) {
64937
64977
  const chain = EVM_CHAINS[network];
64938
64978
  if (!chain) continue;
64939
64979
  if (!leg.payTo || !leg.asset || !leg.maxAmountRequired) continue;
64980
+ if (leg.asset.toLowerCase() !== chain.usdc.toLowerCase()) continue;
64940
64981
  let amountMicro;
64941
64982
  try {
64942
64983
  amountMicro = BigInt(leg.maxAmountRequired);
@@ -64981,7 +65022,7 @@ async function chooseLeg(body, address) {
64981
65022
  const offered = (body.accepts ?? []).map((a) => a.network ?? "?").join(", ") || "none";
64982
65023
  return {
64983
65024
  ok: false,
64984
- reason: `this 402 offers no EVM \`exact\` leg this key can sign (offered: ${offered}). A solana leg needs the compute lane's partially-signed transaction`,
65025
+ reason: `this 402 offers no EVM \`exact\` USDC leg this key can sign (offered: ${offered}). A solana leg needs the compute lane's partially-signed transaction; a leg naming any token but Circle's USDC is never signed`,
64985
65026
  needMicro: null,
64986
65027
  bestHeldMicro: null
64987
65028
  };
@@ -65023,7 +65064,8 @@ function usd(micro) {
65023
65064
  async function signLeg(leg, privateKey) {
65024
65065
  const wallet = new ethers_exports.Wallet(privateKey);
65025
65066
  const now = Math.floor(Date.now() / 1e3);
65026
- const window2 = typeof leg.leg.maxTimeoutSeconds === "number" && leg.leg.maxTimeoutSeconds > 0 ? leg.leg.maxTimeoutSeconds : 600;
65067
+ const asked = typeof leg.leg.maxTimeoutSeconds === "number" && leg.leg.maxTimeoutSeconds > 0 ? leg.leg.maxTimeoutSeconds : 600;
65068
+ const window2 = Math.min(asked, MAX_PAYMENT_WINDOW_SECONDS);
65027
65069
  const authorization = {
65028
65070
  from: wallet.address,
65029
65071
  to: leg.payTo,
@@ -65057,10 +65099,37 @@ async function signLeg(leg, privateKey) {
65057
65099
  from: wallet.address
65058
65100
  };
65059
65101
  }
65102
+ function microOfUsd(raw) {
65103
+ const m = /^\s*\$?(\d+)(?:\.(\d{1,6}))?\s*$/.exec(raw);
65104
+ if (!m) throw new Error(`--max-usd takes dollars, like 1 or 0.5 (got "${raw}")`);
65105
+ return BigInt(m[1]) * 1000000n + BigInt((m[2] ?? "").padEnd(6, "0"));
65106
+ }
65107
+ async function consentToPay(args) {
65108
+ const price = usd(args.leg.amountMicro);
65109
+ if (args.maxUsd !== void 0) {
65110
+ let ceiling;
65111
+ try {
65112
+ ceiling = microOfUsd(args.maxUsd);
65113
+ } catch (err) {
65114
+ return { ok: false, code: "bad_input", reason: err.message };
65115
+ }
65116
+ if (args.leg.amountMicro > ceiling) {
65117
+ return { ok: false, code: "over_max", reason: `${args.what} costs ${price} on ${args.leg.network}, over --max-usd ${usd(ceiling)}: nothing was signed` };
65118
+ }
65119
+ return { ok: true };
65120
+ }
65121
+ if (!args.interactive || !args.ask) {
65122
+ return { ok: false, code: "max_usd_required", reason: `${args.what} costs ${price} on ${args.leg.network}: pass --max-usd with the most it may pay. Nothing was signed` };
65123
+ }
65124
+ const answer = (await args.ask(` Pay ${price} USDC on ${args.leg.network} for ${args.what}? [y/N] `)).trim().toLowerCase();
65125
+ if (answer === "y" || answer === "yes") return { ok: true };
65126
+ return { ok: false, code: "declined", reason: "Nothing paid." };
65127
+ }
65060
65128
 
65061
65129
  // src/lib/compute-wire.ts
65062
65130
  init_constants();
65063
65131
  init_passwords_wire();
65132
+ init_terminal_text();
65064
65133
  var trim3 = (v) => v ? v.trim().replace(/\/+$/, "") : "";
65065
65134
  function computeOrigin() {
65066
65135
  return trim3(process.env.AGENTGATES_COMPUTE_ORIGIN) || "https://api.agentgates.ai";
@@ -65144,7 +65213,7 @@ async function computeCall(args) {
65144
65213
  const text = await res.text().catch(() => "");
65145
65214
  let parsed = {};
65146
65215
  try {
65147
- parsed = text ? JSON.parse(text) : {};
65216
+ parsed = text ? scrubDeep(JSON.parse(text)) : {};
65148
65217
  } catch {
65149
65218
  parsed = { error: text.replace(/\s+/g, " ").trim().slice(0, 300) || `HTTP ${res.status}` };
65150
65219
  }
@@ -65329,7 +65398,7 @@ async function readCompose(file) {
65329
65398
  throw new Error(`could not read the compose file ${file}: ${err.code ?? err.message}`);
65330
65399
  }
65331
65400
  }
65332
- function microOfUsd(raw) {
65401
+ function microOfUsd2(raw) {
65333
65402
  const m = /^\s*\$?(\d+)(?:\.(\d{1,6}))?\s*$/.exec(raw);
65334
65403
  if (!m) throw new Error(`--max-usd takes dollars, like 1 or 0.5 (got "${raw}")`);
65335
65404
  return BigInt(m[1]) * 1000000n + BigInt((m[2] ?? "").padEnd(6, "0"));
@@ -65446,10 +65515,14 @@ async function payFor(opts, args) {
65446
65515
  return;
65447
65516
  }
65448
65517
  const price = usd(leg.amountMicro);
65518
+ if (opts.yes && opts.maxUsd === void 0) {
65519
+ fail(opts, `--yes needs --max-usd, the most this may pay (the price is ${price} on ${leg.network}): nothing was signed`, "max_usd_required", { legs });
65520
+ return;
65521
+ }
65449
65522
  if (opts.maxUsd !== void 0) {
65450
65523
  let ceiling;
65451
65524
  try {
65452
- ceiling = microOfUsd(opts.maxUsd);
65525
+ ceiling = microOfUsd2(opts.maxUsd);
65453
65526
  } catch (err) {
65454
65527
  fail(opts, err.message, "bad_input");
65455
65528
  return;
@@ -65734,6 +65807,35 @@ function emitMachine(opts, machine, extra) {
65734
65807
  var import_picocolors4 = __toESM(require_picocolors(), 1);
65735
65808
  init_passwords_wire();
65736
65809
  init_constants();
65810
+ import { createInterface as createInterface2 } from "node:readline/promises";
65811
+ async function mayPay(leg, what, opts) {
65812
+ const interactive = !opts.json && process.stdin.isTTY === true && process.stdout.isTTY === true;
65813
+ const consent = await consentToPay({
65814
+ leg,
65815
+ maxUsd: opts.maxUsd,
65816
+ interactive,
65817
+ what,
65818
+ ask: async (question) => {
65819
+ const rl = createInterface2({ input: process.stdin, output: process.stdout });
65820
+ try {
65821
+ return await rl.question(question);
65822
+ } catch {
65823
+ return "";
65824
+ } finally {
65825
+ rl.close();
65826
+ }
65827
+ }
65828
+ });
65829
+ if (consent.ok) return true;
65830
+ process.stdout.write(
65831
+ opts.json ? `${JSON.stringify({ ok: false, code: consent.code, error: consent.reason })}
65832
+ ` : `
65833
+ ${consent.code === "declined" ? import_picocolors4.default.dim(consent.reason) : `${import_picocolors4.default.red("\u2717")} ${consent.reason}`}
65834
+
65835
+ `
65836
+ );
65837
+ return false;
65838
+ }
65737
65839
  var SITE = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
65738
65840
  function applyFilters(models, f2) {
65739
65841
  let out = models;
@@ -65941,6 +66043,7 @@ async function inferenceTopUp(amountUsd, opts = {}) {
65941
66043
  `);
65942
66044
  return;
65943
66045
  }
66046
+ if (!await mayPay(choice.leg, `a ${usd(BigInt(Math.round(amountUsd * 1e6)))} top-up`, opts)) return;
65944
66047
  if (!opts.json) process.stdout.write(`
65945
66048
  ${import_picocolors4.default.dim(`paying ${usd(choice.leg.amountMicro)} on ${choice.leg.network}`)}
65946
66049
  `);
@@ -66019,6 +66122,7 @@ async function inferenceAsk(words7, opts = {}) {
66019
66122
  );
66020
66123
  return;
66021
66124
  }
66125
+ if (!await mayPay(choice.leg, "this ask", opts)) return;
66022
66126
  if (!opts.json) process.stdout.write(`
66023
66127
  ${import_picocolors4.default.dim(`paying ${usd(choice.leg.amountMicro)} on ${choice.leg.network}`)}
66024
66128
  `);
@@ -66071,6 +66175,7 @@ init_passwords_wire();
66071
66175
  // src/lib/phone-wire.ts
66072
66176
  init_constants();
66073
66177
  init_passwords_wire();
66178
+ init_terminal_text();
66074
66179
  var INBOUND_ROLES = ["receptionist", "screener", "order-taker", "reservationist", "after-hours", "callback-line", "hotline", "answering-voicemail"];
66075
66180
  async function createPersona(wallet, body) {
66076
66181
  return expect(await signedFetch(wallet, "POST", lanePath(`/personas`), body), "the persona").persona;
@@ -66130,7 +66235,7 @@ async function readCallRecording(wallet, phoneId, id2, owner) {
66130
66235
  const text = await res.text();
66131
66236
  let json2 = null;
66132
66237
  try {
66133
- json2 = text ? JSON.parse(text) : null;
66238
+ json2 = text ? scrubDeep(JSON.parse(text)) : null;
66134
66239
  } catch {
66135
66240
  json2 = null;
66136
66241
  }
@@ -66173,7 +66278,7 @@ function countryCodeFor(countries) {
66173
66278
  function transcriptLines(raw) {
66174
66279
  if (!raw) return [];
66175
66280
  try {
66176
- const parsed = JSON.parse(raw);
66281
+ const parsed = scrubDeep(JSON.parse(raw));
66177
66282
  if (!Array.isArray(parsed)) return [];
66178
66283
  return parsed.filter((l) => !!l && typeof l === "object" && typeof l.role === "string" && typeof l.text === "string" && l.text.length > 0).map((l) => ({ role: l.role, text: l.text }));
66179
66284
  } catch {
@@ -69498,6 +69603,7 @@ function keyWrapAad(ownerWallet, keyId) {
69498
69603
  }
69499
69604
 
69500
69605
  // src/lib/mail-key.ts
69606
+ init_terminal_text();
69501
69607
  var held = /* @__PURE__ */ new Map();
69502
69608
  async function readSealKey(wallet) {
69503
69609
  const out = expectOk(await signedFetch(wallet, "GET", lanePath("/seal-key")), "the mail key");
@@ -69574,9 +69680,9 @@ function openMessage(key, inboxId, m) {
69574
69680
  id: m.id,
69575
69681
  from: m.from ?? "",
69576
69682
  to: m.to,
69577
- subject: m.sealed.subject ? openSubject(key.dataKey, m.sealed.subject, inboxId) : "",
69578
- text: body.text,
69579
- html: body.html,
69683
+ subject: m.sealed.subject ? scrubText(openSubject(key.dataKey, m.sealed.subject, inboxId)) : "",
69684
+ text: scrubText(body.text),
69685
+ html: body.html === null ? null : scrubText(body.html),
69580
69686
  receivedAt: m.receivedAt ?? ""
69581
69687
  };
69582
69688
  }
@@ -69648,6 +69754,7 @@ async function grantedKeyFor(wallet, owner) {
69648
69754
  }
69649
69755
 
69650
69756
  // src/lib/call-seal.ts
69757
+ init_terminal_text();
69651
69758
  var SEALED_RE = /^v1\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/;
69652
69759
  function isSealedCallBlob(value) {
69653
69760
  return typeof value === "string" && SEALED_RE.test(value);
@@ -69668,7 +69775,7 @@ function parseSealedTranscript(text) {
69668
69775
  }
69669
69776
  function openCallTranscript(key, blob, callId) {
69670
69777
  if (!isSealedCallBlob(blob)) throw new MailSealError("bad_blob", "This call carries no sealed transcript.");
69671
- return parseSealedTranscript(openText(key.dataKey, blob, callTranscriptAad(callId)));
69778
+ return scrubDeep(parseSealedTranscript(openText(key.dataKey, blob, callTranscriptAad(callId))));
69672
69779
  }
69673
69780
  function openCallTranscriptQuietly(key, blob, callId) {
69674
69781
  if (!key || !isSealedCallBlob(blob)) return null;
@@ -69807,6 +69914,8 @@ async function payphoneCall(args) {
69807
69914
  const shortfall = need2 && held3 ? `${choice.reason}. The window costs ${need2} and this key holds ${held3}. Send USDC to ${args.address} on base, polygon or arbitrum and it pays for itself` : need2 ? `${choice.reason}. The window costs ${need2}` : choice.reason;
69808
69915
  throw new WireError(402, "payphone_unfunded", shortfall, quote.json);
69809
69916
  }
69917
+ const consent = await args.consent(choice.leg);
69918
+ if (!consent.ok) throw new WireError(402, consent.code, consent.reason, quote.json);
69810
69919
  args.onQuote?.(`paying ${usd(choice.leg.amountMicro)} on ${choice.leg.network}`);
69811
69920
  const signed2 = await signLeg(choice.leg, args.privateKey);
69812
69921
  const payer = new ethers_exports.Wallet(args.privateKey);
@@ -69845,6 +69954,7 @@ async function payphoneRead(payment, asked, what, privateKey) {
69845
69954
  }
69846
69955
 
69847
69956
  // src/commands/phone.ts
69957
+ import { createInterface as createInterface3 } from "node:readline/promises";
69848
69958
  var SITE2 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
69849
69959
  var jsonMode2 = (opts) => opts.json === true || !process.stdout.isTTY;
69850
69960
  function emit2(opts, data4, human) {
@@ -70049,7 +70159,24 @@ async function walkUpToThePayphone(opts, args) {
70049
70159
  onQuote: (note2) => {
70050
70160
  if (!jsonMode2(opts)) process.stderr.write(` ${import_picocolors5.default.dim(note2)}
70051
70161
  `);
70052
- }
70162
+ },
70163
+ // The caller's --max-usd, or a person's yes at the terminal (M7).
70164
+ consent: (leg) => consentToPay({
70165
+ leg,
70166
+ maxUsd: opts.maxUsd,
70167
+ interactive: !jsonMode2(opts) && process.stdin.isTTY === true && process.stdout.isTTY === true,
70168
+ what: `a ${window2}-minute payphone call`,
70169
+ ask: async (question) => {
70170
+ const rl = createInterface3({ input: process.stdin, output: process.stdout });
70171
+ try {
70172
+ return await rl.question(question);
70173
+ } catch {
70174
+ return "";
70175
+ } finally {
70176
+ rl.close();
70177
+ }
70178
+ }
70179
+ })
70053
70180
  });
70054
70181
  const placed = walk.call;
70055
70182
  const paid = usd(walk.paidMicro);
@@ -73319,7 +73446,7 @@ async function onboard(opts = {}) {
73319
73446
  if (stale) put(stale);
73320
73447
  const order = menuOrder(opts.lane, !!account, latestSeen !== null).filter((k) => existing ? k !== "wallet" : true);
73321
73448
  printMenu(put, order, true);
73322
- const rl = createInterface2({ input: process.stdin, output: process.stdout });
73449
+ const rl = createInterface4({ input: process.stdin, output: process.stdout });
73323
73450
  const exitDefault = String(order.indexOf("poke") + 1);
73324
73451
  let first = true;
73325
73452
  let plain = put;
@@ -73477,7 +73604,7 @@ init_passwords_wire();
73477
73604
  init_passwords_seal();
73478
73605
 
73479
73606
  // src/lib/mcp-stdio.ts
73480
- import { createInterface as createInterface3 } from "node:readline";
73607
+ import { createInterface as createInterface5 } from "node:readline";
73481
73608
  var MCP_PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
73482
73609
  var McpToolError = class extends Error {
73483
73610
  constructor(message, detail = {}) {
@@ -73590,7 +73717,7 @@ async function serve(tools, info, { input = process.stdin, output: output2 = pro
73590
73717
  `);
73591
73718
  };
73592
73719
  const inFlight = /* @__PURE__ */ new Set();
73593
- const lines = createInterface3({ input, crlfDelay: Infinity });
73720
+ const lines = createInterface5({ input, crlfDelay: Infinity });
73594
73721
  for await (const line2 of lines) {
73595
73722
  const parsed = parseLine(line2);
73596
73723
  if (!parsed) continue;
@@ -74844,7 +74971,7 @@ async function filesRm(target, opts) {
74844
74971
 
74845
74972
  // src/commands/card.ts
74846
74973
  var import_picocolors15 = __toESM(require_picocolors(), 1);
74847
- import { createInterface as createInterface4 } from "node:readline/promises";
74974
+ import { createInterface as createInterface6 } from "node:readline/promises";
74848
74975
 
74849
74976
  // src/lib/memory-address.ts
74850
74977
  var ADDRESS_FOLDER = "profile";
@@ -75386,7 +75513,7 @@ var QUESTIONS = [
75386
75513
  { field: "zip", ask: "ZIP code", abroad: "Postal code" }
75387
75514
  ];
75388
75515
  async function askAddress() {
75389
- const rl = createInterface4({ input: process.stdin, output: process.stdout });
75516
+ const rl = createInterface6({ input: process.stdin, output: process.stdout });
75390
75517
  const answers = { country: "US", line1: "", line2: "", city: "", region: "", zip: "" };
75391
75518
  try {
75392
75519
  process.stdout.write(`
@@ -76188,6 +76315,7 @@ init_passwords_wire();
76188
76315
  init_lib2();
76189
76316
  init_constants();
76190
76317
  init_passwords_wire();
76318
+ init_terminal_text();
76191
76319
  var path5 = (relative = "") => lanePath(`intents${relative}`);
76192
76320
  function expect3(answer, what) {
76193
76321
  if (answer.status >= 200 && answer.status < 300 && answer.body !== null) return answer.body;
@@ -76249,7 +76377,7 @@ async function readListingPublic(id2) {
76249
76377
  const text = await res.text();
76250
76378
  let body = null;
76251
76379
  try {
76252
- body = JSON.parse(text);
76380
+ body = scrubDeep(JSON.parse(text));
76253
76381
  } catch {
76254
76382
  }
76255
76383
  return expect3({ status: res.status, body, text }, `GET /listings/${id2}`);
@@ -76260,7 +76388,7 @@ async function lookupListingByPhone(phone2) {
76260
76388
  const text = await res.text();
76261
76389
  let body = null;
76262
76390
  try {
76263
- body = JSON.parse(text);
76391
+ body = scrubDeep(JSON.parse(text));
76264
76392
  } catch {
76265
76393
  }
76266
76394
  return expect3({ status: res.status, body, text }, "GET /listings?phone").listing;
@@ -76363,6 +76491,27 @@ async function signEscrow(wallet, group) {
76363
76491
  });
76364
76492
  return { chainId: group.chainId, payment: encodePayment(group.network, signature, authorization) };
76365
76493
  }
76494
+ function releaseWordRefusal(toSign, leg, nowSeconds = Math.floor(Date.now() / 1e3)) {
76495
+ if (!toSign) return null;
76496
+ const fail11 = (why) => `refused to sign the release word: ${why}`;
76497
+ const d = toSign.domain;
76498
+ if (!d || d.name !== "Cov3nantIntent" || d.version !== "1") return fail11("it is not the intents escrow's domain");
76499
+ if (Object.keys(d).sort().join(",") !== "chainId,name,verifyingContract,version") return fail11("the domain carries fields the escrow's does not");
76500
+ const types = toSign.types;
76501
+ if (!types || Object.keys(types).join(",") !== "FunderRelease") return fail11("it is not a FunderRelease");
76502
+ const fields = types.FunderRelease ?? [];
76503
+ if (fields.map((f2) => `${f2.name}:${f2.type}`).join(",") !== "legIndex:uint256,nonce:uint256,deadline:uint256") return fail11("its fields are not the escrow's");
76504
+ const m = toSign.message;
76505
+ if (!m || Object.keys(m).sort().join(",") !== "deadline,legIndex,nonce") return fail11("its message carries fields the escrow's does not");
76506
+ if (![m.legIndex, m.nonce, m.deadline].every((v) => Number.isSafeInteger(v) && v >= 0)) return fail11("its numbers are not whole and non-negative");
76507
+ if (!leg || !leg.escrowAddress || leg.legIndex === null) return fail11("this leg is not held in escrow");
76508
+ if (typeof d.verifyingContract !== "string" || d.verifyingContract.toLowerCase() !== leg.escrowAddress.toLowerCase()) return fail11("it names another deal than this leg's");
76509
+ if (d.chainId !== leg.chainId) return fail11("it names another chain than this leg's");
76510
+ if (m.legIndex !== leg.legIndex) return fail11("it names another leg");
76511
+ const deadline = m.deadline;
76512
+ if (deadline <= nowSeconds || deadline > nowSeconds + 7200) return fail11("its deadline is not within the next two hours");
76513
+ return null;
76514
+ }
76366
76515
  async function wordOnLeg(wallet, askId, offerId, happened, toSign) {
76367
76516
  let signed2 = {};
76368
76517
  if (happened && toSign) {
@@ -76646,6 +76795,11 @@ async function intentsWord(id2, opts) {
76646
76795
  if (happened && said?.transaction) {
76647
76796
  return refuse5(opts, "This leg is on Solana: its word is signed by a Solana wallet, which this key is not.", "svm_word");
76648
76797
  }
76798
+ if (happened && said?.word) {
76799
+ const leg = detail.settlements.find((st) => st.offerId === opts.offer);
76800
+ const refusal = releaseWordRefusal(said.word, leg ? { chainId: leg.chainId, escrowAddress: leg.escrowAddress, legIndex: leg.legIndex } : void 0);
76801
+ if (refusal) return refuse5(opts, refusal, "word_refused");
76802
+ }
76649
76803
  const settlement = await wordOnLeg(wallet, id2, opts.offer, happened, said?.word);
76650
76804
  emit9(opts, { ok: true, settlement }, () => {
76651
76805
  process.stdout.write(`
@@ -77063,6 +77217,7 @@ async function intentsNoShow(askId, opts) {
77063
77217
  var import_picocolors18 = __toESM(require_picocolors(), 1);
77064
77218
  import { createHash as createHash6, randomBytes as randomBytes9 } from "node:crypto";
77065
77219
  init_passwords_wire();
77220
+ init_terminal_text();
77066
77221
  function emit10(opts, data4, human) {
77067
77222
  if (opts.json || !process.stdout.isTTY) {
77068
77223
  process.stdout.write(`${JSON.stringify(data4)}
@@ -77400,7 +77555,7 @@ function askOf(dataKey, owner, ask) {
77400
77555
  const aad = `AGENTGATES-CONVERSATION-v1|turn|${normalizeOwner2(owner)}|${ask.conversationId}|${ask.seq}|${ask.role}${ask.author ? `|${ask.author}|${ask.channel ?? ""}` : ""}`;
77401
77556
  const text = openText(dataKey, ask.ciphertext, aad);
77402
77557
  if (ask.author === "card") {
77403
- const words7 = JSON.parse(text).words ?? "";
77558
+ const words7 = scrubDeep(JSON.parse(text)).words ?? "";
77404
77559
  return words7 ? `Fix: ${words7.split("\n")[0].trim()}` : null;
77405
77560
  }
77406
77561
  const m = /^Asked for a change on site [A-Za-z0-9_-]{22}: ([\s\S]*)$/.exec(text.trim());
@@ -80290,7 +80445,8 @@ async function orderFood(items, opts) {
80290
80445
  if (!jsonMode8) {
80291
80446
  process.stderr.write(
80292
80447
  import_picocolors32.default.yellow(
80293
- `This order is over your saved card's per-order cap (${fmtCents(agentCard.max_per_order_cents)}), so it needs you.
80448
+ agentCard.allowed ? `This order is over your saved card's per-order cap (${fmtCents(agentCard.max_per_order_cents)}), so it needs you.
80449
+ ` : `You have not allowed this login to pay for food with your saved card, so it needs you. Allow "Pay for food" on this agent's page in your Agentgates wallet to let it pay the next ones.
80294
80450
  `
80295
80451
  )
80296
80452
  );
@@ -80348,6 +80504,7 @@ function readAgentCard(res) {
80348
80504
  last4: c.last4,
80349
80505
  max_per_order_cents: typeof c.max_per_order_cents === "number" ? c.max_per_order_cents : 0,
80350
80506
  max_per_day_cents: typeof c.max_per_day_cents === "number" ? c.max_per_day_cents : 0,
80507
+ allowed: c.allowed !== false,
80351
80508
  will_attempt: c.will_attempt === true
80352
80509
  };
80353
80510
  }
@@ -81122,6 +81279,7 @@ init_constants();
81122
81279
  // src/lib/trade-sol.ts
81123
81280
  var import_web3 = __toESM(require_index_cjs(), 1);
81124
81281
  init_constants();
81282
+ init_terminal_text();
81125
81283
  import { promises as fs9 } from "node:fs";
81126
81284
  import * as path6 from "node:path";
81127
81285
  import * as os3 from "node:os";
@@ -81188,7 +81346,7 @@ async function relayPost(pathname, body) {
81188
81346
  const text = await res.text();
81189
81347
  let parsed;
81190
81348
  try {
81191
- parsed = JSON.parse(text);
81349
+ parsed = scrubDeep(JSON.parse(text));
81192
81350
  } catch {
81193
81351
  parsed = { error: text.slice(0, 200) };
81194
81352
  }
@@ -81204,7 +81362,7 @@ async function relayGet(pathname) {
81204
81362
  const text = await res.text();
81205
81363
  let parsed;
81206
81364
  try {
81207
- parsed = JSON.parse(text);
81365
+ parsed = scrubDeep(JSON.parse(text));
81208
81366
  } catch {
81209
81367
  parsed = { error: text.slice(0, 200) };
81210
81368
  }
@@ -82486,6 +82644,7 @@ async function deskSell(coinArg, amount, opts) {
82486
82644
  }
82487
82645
 
82488
82646
  // src/main.ts
82647
+ installServerTextScrub();
82489
82648
  var { version: VERSION } = JSON.parse(readFileSync3(new URL("../package.json", import.meta.url), "utf8"));
82490
82649
  var program2 = new Command();
82491
82650
  program2.name("agentgates").description(
@@ -83016,10 +83175,10 @@ inference.command("key").description("Mint a key that buys turns without the wor
83016
83175
  }
83017
83176
  await inferenceKeyCreate(opts);
83018
83177
  });
83019
- inference.command("topup").argument("<usd>", "dollars to add to the account balance", (v) => Number(v)).description("Buy prepaid balance with one x402 payment from this machine's key. A streamed turn can only be served from a balance.").option("--json", "machine-readable output").action(async (usd6, opts) => {
83178
+ inference.command("topup").argument("<usd>", "dollars to add to the account balance", (v) => Number(v)).description("Buy prepaid balance with one x402 payment from this machine's key. A streamed turn can only be served from a balance.").option("--max-usd <dollars>", "the most this top-up may cost; without it, a person confirms at the terminal").option("--json", "machine-readable output").action(async (usd6, opts) => {
83020
83179
  await inferenceTopUp(usd6, opts);
83021
83180
  });
83022
- inference.command("ask").argument("[words...]", "what to ask, in words").description("One paid ask, signed by this machine's key: the prepaid balance if it covers it, else one x402 payment.").option("--model <id>", "a catalog id (agentgates inference models)").option("--max-tokens <n>", "output ceiling", (v) => parseInt(v, 10)).option("--json", "machine-readable output").action(async (words7, opts) => {
83181
+ inference.command("ask").argument("[words...]", "what to ask, in words").description("One paid ask, signed by this machine's key: the prepaid balance if it covers it, else one x402 payment.").option("--model <id>", "a catalog id (agentgates inference models)").option("--max-tokens <n>", "output ceiling", (v) => parseInt(v, 10)).option("--max-usd <dollars>", "the most an x402-paid ask may cost; without it, a person confirms at the terminal").option("--json", "machine-readable output").action(async (words7, opts) => {
83023
83182
  await inferenceAsk(words7, opts);
83024
83183
  });
83025
83184
  var phone = program2.command("phone").description("Phone numbers on a plan, texts and calls metered, and a walk-up payphone, USDC over x402");
@@ -83027,7 +83186,7 @@ phone.command("pricing").description("Number plans, per-unit usage and the payph
83027
83186
  await phonePricing(opts);
83028
83187
  });
83029
83188
  var callDescription = "Put the AI operator on a real phone call: the number, then what to get done, in words. On your number, or from the house number with none; metered from your balance";
83030
- var registerCall = (parent, name) => parent.command(`${name} <number> [task...]`).description(callDescription).option("--from <phone id or number>", "one of your numbers (default: your first; the house number with none)").option("--house", "force the house number").option("--greeting <line>", "spoken the instant the call connects (up to 300 chars)").option("--voice <name>", "one of the catalog's operator voices").option("--brain <ours|yours>", "who runs the call: our brain (default) or yours over --webhook").option("--webhook <url>", "your brain's door when --brain yours: the transcript is POSTed there, the reply is the next sentence").option("--minutes <n>", "the window this call holds and is cut off at (default: the catalog's operator.minutes)").option("--wait [seconds]", "wait for the call to end and print the transcript and the outcome").option("--payphone", "walk up and pay for the call in USDC: no account, no balance, no sign-in. Used on its own when the balance is empty").option("--json", "machine-readable output").action(async (number2, task, opts) => {
83189
+ var registerCall = (parent, name) => parent.command(`${name} <number> [task...]`).description(callDescription).option("--from <phone id or number>", "one of your numbers (default: your first; the house number with none)").option("--house", "force the house number").option("--greeting <line>", "spoken the instant the call connects (up to 300 chars)").option("--voice <name>", "one of the catalog's operator voices").option("--brain <ours|yours>", "who runs the call: our brain (default) or yours over --webhook").option("--webhook <url>", "your brain's door when --brain yours: the transcript is POSTed there, the reply is the next sentence").option("--minutes <n>", "the window this call holds and is cut off at (default: the catalog's operator.minutes)").option("--wait [seconds]", "wait for the call to end and print the transcript and the outcome").option("--payphone", "walk up and pay for the call in USDC: no account, no balance, no sign-in. Used on its own when the balance is empty").option("--max-usd <dollars>", "the most the payphone may charge; without it, a person confirms at the terminal").option("--json", "machine-readable output").action(async (number2, task, opts) => {
83031
83190
  await phoneCall(number2, task ?? [], opts);
83032
83191
  });
83033
83192
  var registerCalls = (parent, name) => parent.command(`${name} [id]`).description("Your recent calls, or one call with its transcript and outcome (--wait until it ends)").option("--from <phone id or number>", "the number whose calls to read (default: your first; the house calls with none)").option("--house", "the house calls").option("--wait [seconds]", "wait for the call to end").option("--owner <address>", "another account's calls, under a grant it gave this key (the owner runs agentgates passwords allow --agent <you>)").option("--audio <file.wav>", "one call: save its recording (a sealed one is opened with your key and written as PCM16)").option("--did <yes|partly|no>", "one call: did it do what you asked (stored beside the call)").option("--json", "machine-readable output").action(async (id2, opts) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentgates/cli",
3
- "version": "0.84.0",
3
+ "version": "0.85.0",
4
4
  "description": "Wallet operations for AI agents and humans",
5
5
  "keywords": [
6
6
  "crypto",