@agentgates/cli 0.20.0 → 0.25.2

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 +897 -534
  2. package/package.json +1 -1
package/dist/cli.mjs CHANGED
@@ -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.20.0",
6878
+ version: "0.25.2",
6879
6879
  description: "Wallet operations for AI agents and humans",
6880
6880
  keywords: [
6881
6881
  "crypto",
@@ -17475,10 +17475,10 @@ var require_dist = __commonJS({
17475
17475
  if (coerce2) {
17476
17476
  value = struct2.coercer(value, ctx2);
17477
17477
  }
17478
- let status3 = "valid";
17478
+ let status4 = "valid";
17479
17479
  for (const failure of struct2.validator(value, ctx2)) {
17480
17480
  failure.explanation = options.message;
17481
- status3 = "not_valid";
17481
+ status4 = "not_valid";
17482
17482
  yield [failure, void 0];
17483
17483
  }
17484
17484
  for (let [k, v, s] of struct2.entries(value, ctx2)) {
@@ -17491,7 +17491,7 @@ var require_dist = __commonJS({
17491
17491
  });
17492
17492
  for (const t of ts) {
17493
17493
  if (t[0]) {
17494
- status3 = t[0].refinement != null ? "not_refined" : "not_valid";
17494
+ status4 = t[0].refinement != null ? "not_refined" : "not_valid";
17495
17495
  yield [t[0], void 0];
17496
17496
  } else if (coerce2) {
17497
17497
  v = t[1];
@@ -17508,14 +17508,14 @@ var require_dist = __commonJS({
17508
17508
  }
17509
17509
  }
17510
17510
  }
17511
- if (status3 !== "not_valid") {
17511
+ if (status4 !== "not_valid") {
17512
17512
  for (const failure of struct2.refiner(value, ctx2)) {
17513
17513
  failure.explanation = options.message;
17514
- status3 = "not_refined";
17514
+ status4 = "not_refined";
17515
17515
  yield [failure, void 0];
17516
17516
  }
17517
17517
  }
17518
- if (status3 === "valid") {
17518
+ if (status4 === "valid") {
17519
17519
  yield [void 0, value];
17520
17520
  }
17521
17521
  }
@@ -18903,8 +18903,8 @@ var require_tr46 = __commonJS({
18903
18903
  var len = countSymbols(domain_name);
18904
18904
  for (var i = 0; i < len; ++i) {
18905
18905
  var codePoint = domain_name.codePointAt(i);
18906
- var status3 = findStatus(codePoint);
18907
- switch (status3[1]) {
18906
+ var status4 = findStatus(codePoint);
18907
+ switch (status4[1]) {
18908
18908
  case "disallowed":
18909
18909
  hasError = true;
18910
18910
  processed += String.fromCodePoint(codePoint);
@@ -18912,11 +18912,11 @@ var require_tr46 = __commonJS({
18912
18912
  case "ignored":
18913
18913
  break;
18914
18914
  case "mapped":
18915
- processed += String.fromCodePoint.apply(String, status3[2]);
18915
+ processed += String.fromCodePoint.apply(String, status4[2]);
18916
18916
  break;
18917
18917
  case "deviation":
18918
18918
  if (processing_option === PROCESSING_OPTIONS.TRANSITIONAL) {
18919
- processed += String.fromCodePoint.apply(String, status3[2]);
18919
+ processed += String.fromCodePoint.apply(String, status4[2]);
18920
18920
  } else {
18921
18921
  processed += String.fromCodePoint(codePoint);
18922
18922
  }
@@ -18929,7 +18929,7 @@ var require_tr46 = __commonJS({
18929
18929
  hasError = true;
18930
18930
  processed += String.fromCodePoint(codePoint);
18931
18931
  } else {
18932
- processed += String.fromCodePoint.apply(String, status3[2]);
18932
+ processed += String.fromCodePoint.apply(String, status4[2]);
18933
18933
  }
18934
18934
  break;
18935
18935
  case "disallowed_STD3_valid":
@@ -18957,8 +18957,8 @@ var require_tr46 = __commonJS({
18957
18957
  }
18958
18958
  var len = countSymbols(label);
18959
18959
  for (var i = 0; i < len; ++i) {
18960
- var status3 = findStatus(label.codePointAt(i));
18961
- if (processing === PROCESSING_OPTIONS.TRANSITIONAL && status3[1] !== "valid" || processing === PROCESSING_OPTIONS.NONTRANSITIONAL && status3[1] !== "valid" && status3[1] !== "deviation") {
18960
+ var status4 = findStatus(label.codePointAt(i));
18961
+ if (processing === PROCESSING_OPTIONS.TRANSITIONAL && status4[1] !== "valid" || processing === PROCESSING_OPTIONS.NONTRANSITIONAL && status4[1] !== "valid" && status4[1] !== "deviation") {
18962
18962
  error = true;
18963
18963
  break;
18964
18964
  }
@@ -21205,7 +21205,7 @@ var require_lib3 = __commonJS({
21205
21205
  let body = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null;
21206
21206
  let opts = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
21207
21207
  Body.call(this, body, opts);
21208
- const status3 = opts.status || 200;
21208
+ const status4 = opts.status || 200;
21209
21209
  const headers = new Headers(opts.headers);
21210
21210
  if (body != null && !headers.has("Content-Type")) {
21211
21211
  const contentType = extractContentType(body);
@@ -21215,8 +21215,8 @@ var require_lib3 = __commonJS({
21215
21215
  }
21216
21216
  this[INTERNALS$1] = {
21217
21217
  url: opts.url,
21218
- status: status3,
21219
- statusText: opts.statusText || STATUS_CODES[status3],
21218
+ status: status4,
21219
+ statusText: opts.statusText || STATUS_CODES[status4],
21220
21220
  headers,
21221
21221
  counter: opts.counter
21222
21222
  };
@@ -25454,7 +25454,7 @@ var require_eventemitter3 = __commonJS({
25454
25454
  if (listeners.fn) return 1;
25455
25455
  return listeners.length;
25456
25456
  };
25457
- EventEmitter.prototype.emit = function emit5(event, a1, a2, a3, a4, a5) {
25457
+ EventEmitter.prototype.emit = function emit6(event, a1, a2, a3, a4, a5) {
25458
25458
  var evt = prefix ? prefix + event : event;
25459
25459
  if (!this._events[evt]) return false;
25460
25460
  var listeners = this._events[evt], len = arguments.length, args, i;
@@ -30611,9 +30611,9 @@ Message: ${transactionMessage}.
30611
30611
  minContextSlot: options.minContextSlot
30612
30612
  };
30613
30613
  const signature2 = await connection.sendTransaction(transaction, signers, sendOptions);
30614
- let status3;
30614
+ let status4;
30615
30615
  if (transaction.recentBlockhash != null && transaction.lastValidBlockHeight != null) {
30616
- status3 = (await connection.confirmTransaction({
30616
+ status4 = (await connection.confirmTransaction({
30617
30617
  abortSignal: options?.abortSignal,
30618
30618
  signature: signature2,
30619
30619
  blockhash: transaction.recentBlockhash,
@@ -30624,7 +30624,7 @@ Message: ${transactionMessage}.
30624
30624
  nonceInstruction
30625
30625
  } = transaction.nonceInfo;
30626
30626
  const nonceAccountPubkey = nonceInstruction.keys[0].pubkey;
30627
- status3 = (await connection.confirmTransaction({
30627
+ status4 = (await connection.confirmTransaction({
30628
30628
  abortSignal: options?.abortSignal,
30629
30629
  minContextSlot: transaction.minNonceContextSlot,
30630
30630
  nonceAccountPubkey,
@@ -30635,17 +30635,17 @@ Message: ${transactionMessage}.
30635
30635
  if (options?.abortSignal != null) {
30636
30636
  console.warn("sendAndConfirmTransaction(): A transaction with a deprecated confirmation strategy was supplied along with an `abortSignal`. Only transactions having `lastValidBlockHeight` or a combination of `nonceInfo` and `minNonceContextSlot` are abortable.");
30637
30637
  }
30638
- status3 = (await connection.confirmTransaction(signature2, options && options.commitment)).value;
30638
+ status4 = (await connection.confirmTransaction(signature2, options && options.commitment)).value;
30639
30639
  }
30640
- if (status3.err) {
30640
+ if (status4.err) {
30641
30641
  if (signature2 != null) {
30642
30642
  throw new SendTransactionError({
30643
30643
  action: "send",
30644
30644
  signature: signature2,
30645
- transactionMessage: `Status: (${JSON.stringify(status3)})`
30645
+ transactionMessage: `Status: (${JSON.stringify(status4)})`
30646
30646
  });
30647
30647
  }
30648
- throw new Error(`Transaction ${signature2} failed (${JSON.stringify(status3)})`);
30648
+ throw new Error(`Transaction ${signature2} failed (${JSON.stringify(status4)})`);
30649
30649
  }
30650
30650
  return signature2;
30651
30651
  }
@@ -33824,15 +33824,15 @@ Message: ${transactionMessage}.
33824
33824
  } else {
33825
33825
  let signatureStatus;
33826
33826
  while (true) {
33827
- const status3 = await this.getSignatureStatus(signature2);
33828
- if (status3 == null) {
33827
+ const status4 = await this.getSignatureStatus(signature2);
33828
+ if (status4 == null) {
33829
33829
  break;
33830
33830
  }
33831
- if (status3.context.slot < (outcome.slotInWhichNonceDidAdvance ?? minContextSlot)) {
33831
+ if (status4.context.slot < (outcome.slotInWhichNonceDidAdvance ?? minContextSlot)) {
33832
33832
  await sleep3(400);
33833
33833
  continue;
33834
33834
  }
33835
- signatureStatus = status3;
33835
+ signatureStatus = status4;
33836
33836
  break;
33837
33837
  }
33838
33838
  if (signatureStatus?.value) {
@@ -37759,16 +37759,16 @@ Message: ${transactionMessage}.
37759
37759
  const signature2 = await connection.sendRawTransaction(rawTransaction, sendOptions);
37760
37760
  const commitment = options && options.commitment;
37761
37761
  const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature2, commitment);
37762
- const status3 = (await confirmationPromise).value;
37763
- if (status3.err) {
37762
+ const status4 = (await confirmationPromise).value;
37763
+ if (status4.err) {
37764
37764
  if (signature2 != null) {
37765
37765
  throw new SendTransactionError({
37766
37766
  action: sendOptions?.skipPreflight ? "send" : "simulate",
37767
37767
  signature: signature2,
37768
- transactionMessage: `Status: (${JSON.stringify(status3)})`
37768
+ transactionMessage: `Status: (${JSON.stringify(status4)})`
37769
37769
  });
37770
37770
  }
37771
- throw new Error(`Raw transaction ${signature2} failed (${JSON.stringify(status3)})`);
37771
+ throw new Error(`Raw transaction ${signature2} failed (${JSON.stringify(status4)})`);
37772
37772
  }
37773
37773
  return signature2;
37774
37774
  }
@@ -37891,9 +37891,9 @@ var AI_DIRECTIVE = "\n[AI: present the above verbatim inside a markdown code blo
37891
37891
 
37892
37892
  // src/lib/api.ts
37893
37893
  var ApiError = class extends Error {
37894
- constructor(status3, code, message, body) {
37894
+ constructor(status4, code, message, body) {
37895
37895
  super(message);
37896
- this.status = status3;
37896
+ this.status = status4;
37897
37897
  this.code = code;
37898
37898
  this.body = body;
37899
37899
  this.name = "ApiError";
@@ -39111,222 +39111,6 @@ async function inferenceAsk() {
39111
39111
 
39112
39112
  // src/commands/phone.ts
39113
39113
  var import_picocolors5 = __toESM(require_picocolors(), 1);
39114
- var SITE3 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
39115
- var usd2 = (v) => {
39116
- const n2 = Number(v);
39117
- if (Number.isInteger(n2)) return `$${n2}`;
39118
- const [whole, frac = ""] = n2.toFixed(6).replace(/0+$/, "").split(".");
39119
- return `$${whole}.${frac.padEnd(2, "0")}`;
39120
- };
39121
- function phoneSlice(body) {
39122
- const { booth, ...rest } = body;
39123
- const out = {
39124
- ...rest,
39125
- products: (body.products ?? []).filter((p) => p.id === "phone"),
39126
- rungs: (body.rungs ?? []).filter((r) => r.product === "phone"),
39127
- prices: (body.prices ?? []).filter((p) => p.product === "phone")
39128
- };
39129
- if (booth?.call) out.booth = { brief: booth.brief, call: booth.call };
39130
- delete out.payg;
39131
- delete out.sendOverflow;
39132
- return out;
39133
- }
39134
- async function phonePricing(opts) {
39135
- const res = await fetch(`${SITE3}/api/identity/catalog`, { headers: { accept: "application/json" } });
39136
- if (!res.ok) throw new Error(`phone catalog: HTTP ${res.status}`);
39137
- const body = await res.json();
39138
- const slice = phoneSlice(body);
39139
- if (opts.json) {
39140
- process.stdout.write(JSON.stringify(slice, null, 2) + "\n");
39141
- return;
39142
- }
39143
- const product = slice.products?.[0];
39144
- if (!product || product.available === false) {
39145
- process.stdout.write(` ${import_picocolors5.default.dim(product?.brief || "Phone numbers are not on sale right now.")}
39146
- `);
39147
- return;
39148
- }
39149
- const plans = slice.prices ?? [];
39150
- process.stdout.write(`
39151
- ${import_picocolors5.default.bold("PHONE NUMBERS")} ${import_picocolors5.default.dim("texts and calls, on a wallet plan")}
39152
-
39153
- `);
39154
- for (const p of plans) {
39155
- const count = p.phones ?? 1;
39156
- const price = usd2(p.priceUsd).padStart(4);
39157
- const term = `/${p.units} days`.padEnd(9);
39158
- process.stdout.write(` ${import_picocolors5.default.bold(p.rung.padEnd(11))} ${import_picocolors5.default.cyan(price)}${import_picocolors5.default.dim(term)} ${import_picocolors5.default.dim(`${count} number${count === 1 ? "" : "s"}`)}
39159
- `);
39160
- }
39161
- if (plans.length === 0) process.stdout.write(` ${import_picocolors5.default.dim("no plan rungs are priced right now")}
39162
- `);
39163
- const u = slice.phoneUsage;
39164
- if (u) {
39165
- const meter = [
39166
- u.textUsd ? `text ${usd2(u.textUsd)}` : "",
39167
- u.minuteUsd ? `call minute ${usd2(u.minuteUsd)}` : "",
39168
- u.waitCodeUsd !== void 0 ? `wait-code ${Number(u.waitCodeUsd) === 0 ? "free" : usd2(u.waitCodeUsd)}` : ""
39169
- ].filter(Boolean).join(" \xB7 ");
39170
- process.stdout.write(`
39171
- ${import_picocolors5.default.dim(`usage, from the prepaid balance: ${meter}`)}
39172
- `);
39173
- if (u.sendingNote) process.stdout.write(` ${import_picocolors5.default.dim(u.sendingNote)}
39174
- `);
39175
- }
39176
- const call = slice.booth?.call;
39177
- const windows = call?.windows ?? [];
39178
- if (call?.available && windows.length) {
39179
- process.stdout.write(`
39180
- ${import_picocolors5.default.bold("PAYPHONE")} ${import_picocolors5.default.dim("no plan, no number: one payment, one call")}
39181
-
39182
- `);
39183
- const ladder = windows.map((w) => `${w.minutes} min ${usd2(w.priceUsd)}`).join(" ");
39184
- process.stdout.write(` ${import_picocolors5.default.dim(ladder)}
39185
- `);
39186
- }
39187
- const nets = [...new Set((plans[0]?.byNetwork ?? []).map((n2) => n2.network))];
39188
- if (nets.length) process.stdout.write(`
39189
- ${import_picocolors5.default.dim(`USDC on ${nets.join(", ")}`)}
39190
-
39191
- `);
39192
- else process.stdout.write("\n");
39193
- }
39194
- async function phoneCall() {
39195
- process.stdout.write(
39196
- `
39197
- A call signs an x402 payment, and this CLI has no signer yet.
39198
- Call from the wallet, one biometric: ${import_picocolors5.default.cyan(`${SITE3}/phone`)}
39199
- Prices from here: ${import_picocolors5.default.dim("agentgates phone pricing")}
39200
-
39201
- `
39202
- );
39203
- }
39204
-
39205
- // src/commands/email.ts
39206
- var import_picocolors6 = __toESM(require_picocolors(), 1);
39207
- var SITE4 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
39208
- var usd3 = (v) => {
39209
- const n2 = Number(v);
39210
- if (Number.isInteger(n2)) return `$${n2}`;
39211
- const [whole, frac = ""] = n2.toFixed(6).replace(/0+$/, "").split(".");
39212
- return `$${whole}.${frac.padEnd(2, "0")}`;
39213
- };
39214
- var family = (rung) => {
39215
- const base = rung.replace(/-?(month|year)$/, "");
39216
- return base === "" ? "Starter" : base.charAt(0).toUpperCase() + base.slice(1);
39217
- };
39218
- function emailSlice(body) {
39219
- const out = {
39220
- ...body,
39221
- products: (body.products ?? []).filter((p) => p.id === "inbox"),
39222
- rungs: (body.rungs ?? []).filter((r) => r.product === "inbox"),
39223
- prices: (body.prices ?? []).filter((p) => p.product === "inbox")
39224
- };
39225
- for (const k of ["booth", "phoneUsage", "voices", "operator", "countries"]) {
39226
- delete out[k];
39227
- }
39228
- return out;
39229
- }
39230
- async function emailPricing(opts) {
39231
- const res = await fetch(`${SITE4}/api/identity/catalog`, { headers: { accept: "application/json" } });
39232
- if (!res.ok) throw new Error(`email catalog: HTTP ${res.status}`);
39233
- const body = await res.json();
39234
- const slice = emailSlice(body);
39235
- const product = slice.products?.[0];
39236
- if (opts.json) {
39237
- process.stdout.write(JSON.stringify(slice, null, 2) + "\n");
39238
- if (!product || product.available === false) process.exitCode = 1;
39239
- return;
39240
- }
39241
- if (!product || product.available === false) {
39242
- process.stdout.write(` ${import_picocolors6.default.dim(product?.note || product?.brief || "Inboxes are not on sale right now.")}
39243
- `);
39244
- process.exitCode = 1;
39245
- return;
39246
- }
39247
- process.stdout.write(`
39248
- ${import_picocolors6.default.bold("EMAIL")} ${import_picocolors6.default.dim(product.brief || "an inbox on your wallet")}
39249
-
39250
- `);
39251
- const freeInboxes = slice.payg?.inboxes;
39252
- if (freeInboxes) {
39253
- const at = product.domain ? ` @ ${product.domain}` : "";
39254
- process.stdout.write(
39255
- ` ${import_picocolors6.default.bold("free".padEnd(11))} ${import_picocolors6.default.cyan("$0".padStart(4))}${"".padEnd(11)} ${import_picocolors6.default.dim(`${freeInboxes} inbox${freeInboxes === 1 ? "" : "es"}${at}, behind a funded balance`)}
39256
- `
39257
- );
39258
- }
39259
- const plans = slice.prices ?? [];
39260
- const families = [];
39261
- const byFamily = /* @__PURE__ */ new Map();
39262
- for (const p of plans) {
39263
- const f2 = family(p.rung);
39264
- if (!byFamily.has(f2)) {
39265
- byFamily.set(f2, []);
39266
- families.push(f2);
39267
- }
39268
- byFamily.get(f2).push(p);
39269
- }
39270
- for (const f2 of families) {
39271
- const rows = byFamily.get(f2).sort((a, b2) => a.units - b2.units);
39272
- const cells = rows.map((p) => `${import_picocolors6.default.cyan(usd3(p.priceUsd).padStart(4))}${import_picocolors6.default.dim(`/${p.units} days`.padEnd(10))}`).join(" ");
39273
- const lead = rows[0];
39274
- const cap = [
39275
- lead.inboxes ? `${lead.inboxes} inbox${lead.inboxes === 1 ? "" : "es"}` : "",
39276
- lead.sendsPerDay ? `${lead.sendsPerDay} sends/day` : ""
39277
- ].filter(Boolean).join(" \xB7 ");
39278
- process.stdout.write(` ${import_picocolors6.default.bold(f2.padEnd(11))} ${cells} ${import_picocolors6.default.dim(cap)}
39279
- `);
39280
- }
39281
- if (plans.length === 0) process.stdout.write(` ${import_picocolors6.default.dim("no plan rungs are priced right now")}
39282
- `);
39283
- const send2 = slice.sendOverflow?.priceUsd;
39284
- const wait2 = body.phoneUsage?.waitCodeUsd;
39285
- const meter = [
39286
- send2 ? `send ${usd3(send2)}` : "",
39287
- wait2 !== void 0 ? `wait-code ${Number(wait2) === 0 ? "free" : usd3(wait2)}` : ""
39288
- ].filter(Boolean).join(" \xB7 ");
39289
- if (meter) process.stdout.write(`
39290
- ${import_picocolors6.default.dim(`usage, from the prepaid balance: ${meter}`)}
39291
- `);
39292
- process.stdout.write(` ${import_picocolors6.default.dim("receiving costs nothing; the plan sells inboxes and sends per day")}
39293
- `);
39294
- const bal = slice.balance;
39295
- if (bal?.note) process.stdout.write(` ${import_picocolors6.default.dim(bal.note)}
39296
- `);
39297
- else if (bal?.minTopUpUsd) process.stdout.write(` ${import_picocolors6.default.dim(`top up any amount from ${usd3(bal.minTopUpUsd)}`)}
39298
- `);
39299
- const nets = [...new Set((plans[0]?.byNetwork ?? []).map((n2) => n2.network))];
39300
- if (nets.length) process.stdout.write(`
39301
- ${import_picocolors6.default.dim(`USDC on ${nets.join(", ")}`)}
39302
-
39303
- `);
39304
- else process.stdout.write("\n");
39305
- }
39306
- function emailDoor(first) {
39307
- process.stdout.write(
39308
- `
39309
- ${first}, and this CLI has no signer yet.
39310
- Do it from the wallet, one biometric: ${import_picocolors6.default.cyan(`${SITE4}/email`)}
39311
- Prices from here: ${import_picocolors6.default.dim("agentgates email pricing")}
39312
-
39313
- `
39314
- );
39315
- }
39316
- async function emailCreate() {
39317
- emailDoor("An inbox is created under your wallet's own signature");
39318
- }
39319
- async function emailSend() {
39320
- emailDoor("A send signs with your wallet and draws from its balance");
39321
- }
39322
-
39323
- // src/commands/passwords.ts
39324
- var import_picocolors8 = __toESM(require_picocolors(), 1);
39325
- import { readFileSync } from "node:fs";
39326
- import { randomBytes as randomBytes7 } from "node:crypto";
39327
-
39328
- // src/commands/session.ts
39329
- var import_picocolors7 = __toESM(require_picocolors(), 1);
39330
39114
 
39331
39115
  // src/lib/passwords-key.ts
39332
39116
  import { promises as fs7 } from "node:fs";
@@ -52510,7 +52294,7 @@ var TransactionReceipt = class {
52510
52294
  logsBloom,
52511
52295
  logs,
52512
52296
  //byzantium,
52513
- status: status3,
52297
+ status: status4,
52514
52298
  root
52515
52299
  } = this;
52516
52300
  return {
@@ -52530,7 +52314,7 @@ var TransactionReceipt = class {
52530
52314
  logs,
52531
52315
  logsBloom,
52532
52316
  root,
52533
- status: status3,
52317
+ status: status4,
52534
52318
  to
52535
52319
  };
52536
52320
  }
@@ -62868,11 +62652,21 @@ function identityOrigin() {
62868
62652
  function siteOrigin() {
62869
62653
  return trim2(process.env.AGENTGATES_ORIGIN) || "https://agentgates.ai";
62870
62654
  }
62871
- var LANE = "/api/identity";
62655
+ var 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" };
62656
+ var SERVICE_HEADS = /* @__PURE__ */ new Set(["booth", "booths", "browser", "passwords", "phones", "inboxes", "calls", "personas", "playbooks"]);
62657
+ var PASSWORDS_USE_PINNED_BY_BOX = false;
62658
+ function lanePath(relative) {
62659
+ const trimmed = relative.replace(/^\/api\/identity/, "").replace(/^\/+/, "");
62660
+ const [head, ...rest] = trimmed.split("/");
62661
+ if (PASSWORDS_USE_PINNED_BY_BOX && head === "passwords" && rest.length === 2 && rest[1] === "use") return `/api/identity/${trimmed}`;
62662
+ const mapped = ACCOUNT_HEADS[head] ?? (SERVICE_HEADS.has(head) ? head : null);
62663
+ if (!mapped) throw new Error(`no public path for ${relative}`);
62664
+ return `/api/${[mapped, ...rest].join("/")}`;
62665
+ }
62872
62666
  var WireError = class extends Error {
62873
- constructor(status3, code, message, body) {
62667
+ constructor(status4, code, message, body) {
62874
62668
  super(message);
62875
- this.status = status3;
62669
+ this.status = status4;
62876
62670
  this.code = code;
62877
62671
  this.body = body;
62878
62672
  this.name = "WireError";
@@ -62906,7 +62700,7 @@ function lastAuthVia() {
62906
62700
  function loginKeyWasRevoked() {
62907
62701
  return revokedNoticed;
62908
62702
  }
62909
- var KEYS_DOOR = /\/keys(\/|$)/;
62703
+ var SIGNED_DOORS = /\/keys(\/|$)|\/passwords\/[A-Za-z0-9_-]{1,64}\/use$/;
62910
62704
  async function signedFetch(wallet, method, path7, body, timeoutMs = 13e4) {
62911
62705
  const once = async (viaKey) => {
62912
62706
  const headers = {
@@ -62936,7 +62730,7 @@ async function signedFetch(wallet, method, path7, body, timeoutMs = 13e4) {
62936
62730
  lastVia = viaKey && loginKey ? "key" : "signature";
62937
62731
  return { status: res.status, body: json2, text };
62938
62732
  };
62939
- const useKey = !!loginKey && !KEYS_DOOR.test(path7);
62733
+ const useKey = !!loginKey && !SIGNED_DOORS.test(path7);
62940
62734
  const answer = await once(useKey);
62941
62735
  if (useKey && answer.status === 401) {
62942
62736
  const signed2 = await once(false);
@@ -62951,15 +62745,15 @@ async function signedFetch(wallet, method, path7, body, timeoutMs = 13e4) {
62951
62745
  return answer;
62952
62746
  }
62953
62747
  async function listLoginKeys(wallet) {
62954
- const answer = await signedFetch(wallet, "GET", `${LANE}/keys`);
62748
+ const answer = await signedFetch(wallet, "GET", lanePath(`/keys`));
62955
62749
  return expectOk(answer, "login keys").keys ?? [];
62956
62750
  }
62957
62751
  async function createLoginKey(wallet, name) {
62958
- const answer = await signedFetch(wallet, "POST", `${LANE}/keys`, { name });
62752
+ const answer = await signedFetch(wallet, "POST", lanePath(`/keys`), { name });
62959
62753
  return expectOk(answer, "login key mint");
62960
62754
  }
62961
62755
  async function revokeLoginKey(wallet, id2) {
62962
- const answer = await signedFetch(wallet, "POST", `${LANE}/keys`, { revoke: id2 });
62756
+ const answer = await signedFetch(wallet, "POST", lanePath(`/keys`), { revoke: id2 });
62963
62757
  return expectOk(answer, "login key revoke");
62964
62758
  }
62965
62759
  function expectOk(answer, what) {
@@ -62972,7 +62766,7 @@ function expectOk(answer, what) {
62972
62766
  async function readAttestation() {
62973
62767
  let res;
62974
62768
  try {
62975
- res = await fetch(`${identityOrigin()}${LANE}/passwords/attestation`, {
62769
+ res = await fetch(`${identityOrigin()}${lanePath("/passwords/attestation")}`, {
62976
62770
  headers: { accept: "application/json", "user-agent": CLI_USER_AGENT },
62977
62771
  signal: AbortSignal.timeout(6e4)
62978
62772
  });
@@ -62987,30 +62781,30 @@ async function readAttestation() {
62987
62781
  return body;
62988
62782
  }
62989
62783
  async function listRows(wallet) {
62990
- const out = expectOk(await signedFetch(wallet, "GET", `${LANE}/passwords`), "list");
62784
+ const out = expectOk(await signedFetch(wallet, "GET", lanePath(`/passwords`)), "list");
62991
62785
  return { passwords: out.passwords ?? [], permitted: out.permitted ?? [] };
62992
62786
  }
62993
62787
  async function storeRow(wallet, body) {
62994
- const out = expectOk(await signedFetch(wallet, "POST", `${LANE}/passwords`, body), "store");
62788
+ const out = expectOk(await signedFetch(wallet, "POST", lanePath(`/passwords`), body), "store");
62995
62789
  return out.password;
62996
62790
  }
62997
62791
  async function revealRow(wallet, id2) {
62998
- const out = expectOk(await signedFetch(wallet, "POST", `${LANE}/passwords/${encodeURIComponent(id2)}/reveal`), "reveal");
62792
+ const out = expectOk(await signedFetch(wallet, "POST", lanePath(`/passwords/${encodeURIComponent(id2)}/reveal`)), "reveal");
62999
62793
  return out.passkeyBlob;
63000
62794
  }
63001
62795
  async function postPermit(wallet, signed2) {
63002
62796
  const out = expectOk(
63003
- await signedFetch(wallet, "POST", `${LANE}/passwords/permits`, { typedData: signed2.typedData, signature: signed2.signature }),
62797
+ await signedFetch(wallet, "POST", lanePath(`/passwords/permits`), { typedData: signed2.typedData, signature: signed2.signature }),
63004
62798
  "permit"
63005
62799
  );
63006
62800
  return out.permit;
63007
62801
  }
63008
62802
  async function postUse(wallet, id2, body, timeoutMs = 2e5) {
63009
- return signedFetch(wallet, "POST", `${LANE}/passwords/${encodeURIComponent(id2)}/use`, body, timeoutMs);
62803
+ return signedFetch(wallet, "POST", lanePath(`/passwords/${encodeURIComponent(id2)}/use`), body, timeoutMs);
63010
62804
  }
63011
62805
  async function withdrawInvite(wallet, envelope, signature) {
63012
62806
  return expectOk(
63013
- await signedFetch(wallet, "POST", `${LANE}/passwords/invites/withdraw`, { invite: { envelope, signature } }),
62807
+ await signedFetch(wallet, "POST", lanePath(`/passwords/invites/withdraw`), { invite: { envelope, signature } }),
63014
62808
  "withdraw"
63015
62809
  );
63016
62810
  }
@@ -63147,10 +62941,483 @@ async function requirePasswordsKey() {
63147
62941
  const fromEnv = (process.env.AGENTGATES_PASSWORDS_SEED || "").trim();
63148
62942
  if (fromEnv) return keysOf(stateOf(normaliseSeed(fromEnv, "AGENTGATES_PASSWORDS_SEED")));
63149
62943
  const existing = await loadPasswordsKey();
63150
- 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.");
62944
+ if (!existing) throw new Error("no account on this machine yet: run `agentgates init` first, or set AGENTGATES_PASSWORDS_SEED to twelve words.");
63151
62945
  return existing;
63152
62946
  }
63153
62947
 
62948
+ // src/lib/phone-wire.ts
62949
+ var TERMINAL = /* @__PURE__ */ new Set(["done", "failed", "no_answer"]);
62950
+ async function readOperator() {
62951
+ let res;
62952
+ try {
62953
+ res = await fetch(`${siteOrigin()}/api/account/catalog`, { headers: { accept: "application/json", "user-agent": CLI_USER_AGENT } });
62954
+ } catch (err) {
62955
+ throw new WireError(0, "network_error", `could not reach ${siteOrigin()}: ${err.message}`, null);
62956
+ }
62957
+ if (!res.ok) throw new WireError(res.status, null, `identity catalog: HTTP ${res.status}`, null);
62958
+ const body = await res.json();
62959
+ return { operator: body.operator ?? null, countries: body.countries ?? [] };
62960
+ }
62961
+ function expect(answer, what) {
62962
+ if (answer.status >= 200 && answer.status < 300 && answer.body) return answer.body;
62963
+ const body = answer.body ?? null;
62964
+ const sentence = typeof body?.error === "string" ? body.error : answer.text.slice(0, 300) || `${what}: HTTP ${answer.status}`;
62965
+ const code = typeof body?.code === "string" ? body.code : null;
62966
+ throw new WireError(answer.status, code, sentence, answer.body);
62967
+ }
62968
+ async function listNumbers(wallet) {
62969
+ const answer = await signedFetch(wallet, "GET", lanePath(`/booths`));
62970
+ return (expect(answer, "numbers").phones ?? []).filter((p) => p.status === "active");
62971
+ }
62972
+ async function placeCall(wallet, phoneId, body) {
62973
+ const path7 = phoneId ? lanePath(`/phones/${encodeURIComponent(phoneId)}/calls`) : lanePath(`/calls`);
62974
+ const answer = await signedFetch(wallet, "POST", path7, body);
62975
+ const out = expect(answer, "call");
62976
+ return { callId: out.callId, call: out.call, perMinuteUsd: out.perMinuteUsd ?? "", from: phoneId ? "number" : "house" };
62977
+ }
62978
+ async function readCall(wallet, phoneId, id2) {
62979
+ const path7 = phoneId ? lanePath(`/phones/${encodeURIComponent(phoneId)}/calls/${encodeURIComponent(id2)}`) : lanePath(`/calls/${encodeURIComponent(id2)}`);
62980
+ const answer = await signedFetch(wallet, "GET", path7);
62981
+ return expect(answer, "call").call;
62982
+ }
62983
+ async function listCalls(wallet, phoneId) {
62984
+ const path7 = phoneId ? lanePath(`/phones/${encodeURIComponent(phoneId)}/calls`) : lanePath(`/calls`);
62985
+ const answer = await signedFetch(wallet, "GET", path7);
62986
+ return expect(answer, "calls").calls ?? [];
62987
+ }
62988
+ async function waitForCall(wallet, phoneId, id2, { maxSeconds = 720, everyMs = 5e3, onTick } = {}) {
62989
+ const until = Date.now() + maxSeconds * 1e3;
62990
+ for (; ; ) {
62991
+ const call = await readCall(wallet, phoneId, id2);
62992
+ onTick?.(call);
62993
+ if (TERMINAL.has(call.status) || Date.now() >= until) return call;
62994
+ await new Promise((r) => setTimeout(r, everyMs));
62995
+ }
62996
+ }
62997
+ function toE164(raw, countryCode) {
62998
+ const t = raw.trim();
62999
+ if (/^\+\d{7,15}$/.test(t)) return t;
63000
+ const digits = t.replace(/[\s().-]/g, "");
63001
+ if (/^\+\d{7,15}$/.test(digits)) return digits;
63002
+ if (/^\d{10}$/.test(digits) && countryCode) return `${countryCode}${digits}`;
63003
+ if (/^1\d{10}$/.test(digits) && countryCode === "+1") return `+${digits}`;
63004
+ return null;
63005
+ }
63006
+ function countryCodeFor(countries) {
63007
+ const first = countries[0];
63008
+ if (!first) return null;
63009
+ return first === "US" || first === "CA" ? "+1" : null;
63010
+ }
63011
+ function transcriptLines(raw) {
63012
+ if (!raw) return [];
63013
+ try {
63014
+ const parsed = JSON.parse(raw);
63015
+ if (!Array.isArray(parsed)) return [];
63016
+ 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 }));
63017
+ } catch {
63018
+ return [];
63019
+ }
63020
+ }
63021
+
63022
+ // src/commands/phone.ts
63023
+ var SITE3 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
63024
+ var jsonMode = (opts) => opts.json === true || !process.stdout.isTTY;
63025
+ function emit2(opts, data4, human) {
63026
+ if (jsonMode(opts)) {
63027
+ process.stdout.write(JSON.stringify(data4, null, 2) + "\n");
63028
+ return;
63029
+ }
63030
+ human();
63031
+ }
63032
+ function refuse(opts, error, code, extra = {}) {
63033
+ if (jsonMode(opts)) {
63034
+ process.stdout.write(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
63035
+ } else {
63036
+ process.stderr.write(` ${error}${code ? import_picocolors5.default.dim(` (${code})`) : ""}
63037
+ `);
63038
+ }
63039
+ process.exit(1);
63040
+ }
63041
+ function failFrom(opts, err) {
63042
+ if (err instanceof WireError) return refuse(opts, err.message, err.code, { status: err.status });
63043
+ return refuse(opts, err.message ?? String(err), null);
63044
+ }
63045
+ var usd2 = (v) => {
63046
+ const n2 = Number(v);
63047
+ if (Number.isInteger(n2)) return `$${n2}`;
63048
+ const [whole, frac = ""] = n2.toFixed(6).replace(/0+$/, "").split(".");
63049
+ return `$${whole}.${frac.padEnd(2, "0")}`;
63050
+ };
63051
+ var when = (iso) => iso ? iso.replace("T", " ").slice(0, 16) : "";
63052
+ var seconds = (s) => s > 0 ? s >= 60 ? `${Math.floor(s / 60)}m ${s % 60}s` : `${s}s` : "";
63053
+ var STATUS_COLOR = {
63054
+ queued: import_picocolors5.default.dim,
63055
+ active: import_picocolors5.default.cyan,
63056
+ done: import_picocolors5.default.green,
63057
+ failed: import_picocolors5.default.red,
63058
+ no_answer: import_picocolors5.default.dim
63059
+ };
63060
+ var STATUS_WORD = { queued: "dialing", active: "on the line", done: "ended", failed: "failed", no_answer: "no answer" };
63061
+ var status = (s) => (STATUS_COLOR[s] ?? import_picocolors5.default.dim)((STATUS_WORD[s] ?? s).padEnd(12));
63062
+ function phoneSlice(body) {
63063
+ const { booth, ...rest } = body;
63064
+ const out = {
63065
+ ...rest,
63066
+ products: (body.products ?? []).filter((p) => p.id === "phone"),
63067
+ rungs: (body.rungs ?? []).filter((r) => r.product === "phone"),
63068
+ prices: (body.prices ?? []).filter((p) => p.product === "phone")
63069
+ };
63070
+ if (booth?.call) out.booth = { brief: booth.brief, call: booth.call };
63071
+ delete out.payg;
63072
+ delete out.sendOverflow;
63073
+ return out;
63074
+ }
63075
+ async function phonePricing(opts) {
63076
+ const res = await fetch(`${SITE3}/api/account/catalog`, { headers: { accept: "application/json" } });
63077
+ if (!res.ok) throw new Error(`phone catalog: HTTP ${res.status}`);
63078
+ const body = await res.json();
63079
+ const slice = phoneSlice(body);
63080
+ if (opts.json) {
63081
+ process.stdout.write(JSON.stringify(slice, null, 2) + "\n");
63082
+ return;
63083
+ }
63084
+ const product = slice.products?.[0];
63085
+ if (!product || product.available === false) {
63086
+ process.stdout.write(` ${import_picocolors5.default.dim(product?.brief || "Phone numbers are not on sale right now.")}
63087
+ `);
63088
+ return;
63089
+ }
63090
+ const plans = slice.prices ?? [];
63091
+ process.stdout.write(`
63092
+ ${import_picocolors5.default.bold("PHONE NUMBERS")} ${import_picocolors5.default.dim("texts and calls, on a wallet plan")}
63093
+
63094
+ `);
63095
+ for (const p of plans) {
63096
+ const count = p.phones ?? 1;
63097
+ const price = usd2(p.priceUsd).padStart(4);
63098
+ const term = `/${p.units} days`.padEnd(9);
63099
+ process.stdout.write(` ${import_picocolors5.default.bold(p.rung.padEnd(11))} ${import_picocolors5.default.cyan(price)}${import_picocolors5.default.dim(term)} ${import_picocolors5.default.dim(`${count} number${count === 1 ? "" : "s"}`)}
63100
+ `);
63101
+ }
63102
+ if (plans.length === 0) process.stdout.write(` ${import_picocolors5.default.dim("no plan rungs are priced right now")}
63103
+ `);
63104
+ const u = slice.phoneUsage;
63105
+ if (u) {
63106
+ const meter = [
63107
+ u.textUsd ? `text ${usd2(u.textUsd)}` : "",
63108
+ u.minuteUsd ? `call minute ${usd2(u.minuteUsd)}` : "",
63109
+ u.waitCodeUsd !== void 0 ? `wait-code ${Number(u.waitCodeUsd) === 0 ? "free" : usd2(u.waitCodeUsd)}` : ""
63110
+ ].filter(Boolean).join(" \xB7 ");
63111
+ process.stdout.write(`
63112
+ ${import_picocolors5.default.dim(`usage, from the prepaid balance: ${meter}`)}
63113
+ `);
63114
+ if (u.sendingNote) process.stdout.write(` ${import_picocolors5.default.dim(u.sendingNote)}
63115
+ `);
63116
+ }
63117
+ const op = slice.operator;
63118
+ if (op?.available && op.minuteUsd) {
63119
+ process.stdout.write(`
63120
+ ${import_picocolors5.default.bold("THE OPERATOR")} ${import_picocolors5.default.dim("our brain, voice and ears on the line; the transcript and the outcome back")}
63121
+
63122
+ `);
63123
+ process.stdout.write(` ${import_picocolors5.default.cyan(usd2(op.minuteUsd))} ${import_picocolors5.default.dim(`a minute, all in, up to ${op.maxMinutes ?? "?"} minutes a call, from the prepaid balance`)}
63124
+ `);
63125
+ process.stdout.write(` ${import_picocolors5.default.dim(op.house ? 'on your number, or from the house number with none: agentgates call <number> "<what to get done>"' : 'on your number: agentgates call <number> "<what to get done>"')}
63126
+ `);
63127
+ } else if (op?.note) {
63128
+ process.stdout.write(`
63129
+ ${import_picocolors5.default.dim(op.note)}
63130
+ `);
63131
+ }
63132
+ const call = slice.booth?.call;
63133
+ const windows = call?.windows ?? [];
63134
+ if (call?.available && windows.length) {
63135
+ process.stdout.write(`
63136
+ ${import_picocolors5.default.bold("PAYPHONE")} ${import_picocolors5.default.dim("no plan, no number, no account: one x402 payment, one call")}
63137
+
63138
+ `);
63139
+ const ladder = windows.map((w) => `${w.minutes} min ${usd2(w.priceUsd)}${w.operatorPriceUsd ? import_picocolors5.default.dim(` (${usd2(w.operatorPriceUsd)} with the operator)`) : ""}`).join(" ");
63140
+ process.stdout.write(` ${ladder}
63141
+ `);
63142
+ }
63143
+ const nets = [...new Set((plans[0]?.byNetwork ?? []).map((n2) => n2.network))];
63144
+ if (nets.length) process.stdout.write(`
63145
+ ${import_picocolors5.default.dim(`USDC on ${nets.join(", ")}`)}
63146
+
63147
+ `);
63148
+ else process.stdout.write("\n");
63149
+ }
63150
+ function printCall(c, from, perMinuteUsd, full) {
63151
+ process.stdout.write(`
63152
+ ${status(c.status)} ${import_picocolors5.default.bold(c.id)} ${import_picocolors5.default.dim(c.peer)}${from ? import_picocolors5.default.dim(` from ${from}`) : ""}${seconds(c.seconds) ? import_picocolors5.default.dim(` ${seconds(c.seconds)}`) : ""}
63153
+ `);
63154
+ if (c.task) process.stdout.write(` ${c.task}
63155
+ `);
63156
+ if (perMinuteUsd) process.stdout.write(` ${import_picocolors5.default.dim(`${usd2(perMinuteUsd)} a minute, from the balance`)}
63157
+ `);
63158
+ if (c.billedUsd) process.stdout.write(` ${import_picocolors5.default.dim(`billed ${usd2(c.billedUsd)}`)}
63159
+ `);
63160
+ const lines = transcriptLines(c.transcript);
63161
+ const outcome = lines.find((l) => l.role === "outcome");
63162
+ if (outcome) process.stdout.write(`
63163
+ ${import_picocolors5.default.bold("Outcome")}
63164
+ ${outcome.text}
63165
+ `);
63166
+ if (full) {
63167
+ const said = lines.filter((l) => l.role !== "outcome");
63168
+ if (said.length) {
63169
+ process.stdout.write(`
63170
+ ${import_picocolors5.default.bold("Transcript")}
63171
+ `);
63172
+ for (const l of said) process.stdout.write(` ${import_picocolors5.default.dim((l.role === "agent" ? "operator" : l.role).padEnd(9))} ${l.text}
63173
+ `);
63174
+ }
63175
+ if (c.recordingUrl) process.stdout.write(`
63176
+ ${import_picocolors5.default.dim("recording:")} ${c.recordingUrl}
63177
+ `);
63178
+ }
63179
+ process.stdout.write("\n");
63180
+ }
63181
+ async function phoneCall(toRaw, words7, opts) {
63182
+ const task = words7.join(" ").trim();
63183
+ const brain = opts.brain === "yours" ? "yours" : "ours";
63184
+ if (!task && brain === "ours") return refuse(opts, 'say what the call is for: agentgates call +14155550142 "ask if they have a table for two at 8"', "bad_request");
63185
+ if (brain === "yours" && !opts.webhook) return refuse(opts, "--brain yours needs --webhook <url>: the transcript is POSTed there and the reply is the next sentence", "bad_request");
63186
+ if (opts.from && opts.house) return refuse(opts, "--from names one of your numbers and --house forces the house number: one or the other", "bad_request");
63187
+ try {
63188
+ const { operator, countries } = await readOperator();
63189
+ if (!operator?.available) return refuse(opts, operator?.note ?? "the AI operator is not open on this deployment", "calls_dark");
63190
+ const to = toE164(toRaw, countryCodeFor(countries));
63191
+ if (!to) return refuse(opts, `"${toRaw}" is not a number this lane dials: E.164 (+14155550142), or ten digits in ${countries[0] ?? "the lane's country"}`, "bad_request");
63192
+ const keys2 = await requirePasswordsKey();
63193
+ let phoneId = null;
63194
+ let fromNumber = null;
63195
+ if (!opts.house) {
63196
+ const numbers = await listNumbers(keys2.wallet);
63197
+ const picked = opts.from ? numbers.find((n2) => n2.id === opts.from || n2.number === opts.from) ?? null : numbers[0] ?? null;
63198
+ if (opts.from && !picked) return refuse(opts, `no active number "${opts.from}" under this account: agentgates phone calls lists them`, "not_found");
63199
+ if (picked) {
63200
+ phoneId = picked.id;
63201
+ fromNumber = picked.number;
63202
+ }
63203
+ }
63204
+ if (!phoneId && operator.house === false) {
63205
+ return refuse(opts, "no number under this account and no house number stands right now: a phone plan (agentgates phone pricing) puts one on it", "pool_empty");
63206
+ }
63207
+ const body = { to, task, brain, persona: { name: "Riley" } };
63208
+ if (opts.webhook) body.webhook = opts.webhook;
63209
+ if (opts.greeting) body.greeting = opts.greeting.slice(0, 300);
63210
+ if (opts.voice) body.voice = opts.voice;
63211
+ const placed = await placeCall(keys2.wallet, phoneId, body);
63212
+ const from = fromNumber ?? "the house number";
63213
+ if (!opts.wait) {
63214
+ emit2(opts, { ok: true, from: placed.from, phoneId, callId: placed.callId, call: placed.call, perMinuteUsd: placed.perMinuteUsd, via: lastAuthVia(), loginKeyRevoked: loginKeyWasRevoked() }, () => {
63215
+ printCall(placed.call, from, placed.perMinuteUsd, false);
63216
+ process.stdout.write(` ${import_picocolors5.default.dim(`read it back: agentgates calls ${placed.callId} --wait`)}
63217
+
63218
+ `);
63219
+ });
63220
+ return;
63221
+ }
63222
+ const maxSeconds = typeof opts.wait === "string" ? Math.max(10, Number(opts.wait) || 0) : Math.max(120, (operator.maxMinutes ?? 10) * 60 + 60);
63223
+ let last = "";
63224
+ const ended = await waitForCall(keys2.wallet, phoneId, placed.callId, {
63225
+ maxSeconds,
63226
+ onTick: (c) => {
63227
+ if (jsonMode(opts) || c.status === last) return;
63228
+ last = c.status;
63229
+ process.stderr.write(` ${import_picocolors5.default.dim(STATUS_WORD[c.status] ?? c.status)}
63230
+ `);
63231
+ }
63232
+ });
63233
+ emit2(opts, { ok: TERMINAL.has(ended.status), from: placed.from, phoneId, callId: ended.id, call: ended, perMinuteUsd: placed.perMinuteUsd }, () => {
63234
+ printCall(ended, from, placed.perMinuteUsd, true);
63235
+ if (!TERMINAL.has(ended.status)) process.stdout.write(` ${import_picocolors5.default.dim(`still ${STATUS_WORD[ended.status] ?? ended.status}; read it later: agentgates calls ${ended.id} --wait`)}
63236
+
63237
+ `);
63238
+ });
63239
+ if (ended.status === "failed") process.exitCode = 1;
63240
+ } catch (err) {
63241
+ failFrom(opts, err);
63242
+ }
63243
+ }
63244
+ async function phoneCalls(id2, opts) {
63245
+ try {
63246
+ const keys2 = await requirePasswordsKey();
63247
+ const numbers = opts.house ? [] : await listNumbers(keys2.wallet);
63248
+ const picked = opts.from ? numbers.find((n2) => n2.id === opts.from || n2.number === opts.from) ?? null : numbers[0] ?? null;
63249
+ if (opts.from && !picked) return refuse(opts, `no active number "${opts.from}" under this account`, "not_found");
63250
+ const phoneId = picked?.id ?? null;
63251
+ const from = picked?.number ?? "the house number";
63252
+ if (id2) {
63253
+ let door = phoneId;
63254
+ const read = async () => {
63255
+ try {
63256
+ return await readCall(keys2.wallet, door, id2);
63257
+ } catch (err) {
63258
+ if (door && err instanceof WireError && err.status === 404) {
63259
+ door = null;
63260
+ return readCall(keys2.wallet, null, id2);
63261
+ }
63262
+ throw err;
63263
+ }
63264
+ };
63265
+ const first = await read();
63266
+ const call = opts.wait && !TERMINAL.has(first.status) ? await waitForCall(keys2.wallet, door, id2, { maxSeconds: typeof opts.wait === "string" ? Math.max(10, Number(opts.wait) || 0) : 720 }) : first;
63267
+ emit2(opts, { ok: true, call, from: door ? "number" : "house" }, () => printCall(call, door ? from : "the house number", null, true));
63268
+ return;
63269
+ }
63270
+ const calls = await listCalls(keys2.wallet, phoneId);
63271
+ emit2(opts, { ok: true, wallet: keys2.wallet.address, from: phoneId ? "number" : "house", phoneId, numbers: numbers.map((n2) => ({ id: n2.id, number: n2.number })), calls }, () => {
63272
+ process.stdout.write(`
63273
+ ${import_picocolors5.default.bold("YOUR CALLS")} ${import_picocolors5.default.dim(`${keys2.wallet.address} \xB7 ${from}`)}
63274
+
63275
+ `);
63276
+ if (calls.length === 0) {
63277
+ process.stdout.write(` ${import_picocolors5.default.dim('none yet: agentgates call <number> "<what to get done>"')}
63278
+
63279
+ `);
63280
+ return;
63281
+ }
63282
+ for (const c of calls) {
63283
+ process.stdout.write(` ${status(c.status)} ${c.id} ${import_picocolors5.default.dim(c.peer.padEnd(16))} ${import_picocolors5.default.dim(seconds(c.seconds).padEnd(8))} ${import_picocolors5.default.dim(when(c.startedAt ?? c.createdAt))}
63284
+ `);
63285
+ if (c.task) process.stdout.write(` ${c.task.length > 90 ? `${c.task.slice(0, 89)}\u2026` : c.task}
63286
+ `);
63287
+ }
63288
+ process.stdout.write("\n");
63289
+ });
63290
+ } catch (err) {
63291
+ failFrom(opts, err);
63292
+ }
63293
+ }
63294
+
63295
+ // src/commands/email.ts
63296
+ var import_picocolors6 = __toESM(require_picocolors(), 1);
63297
+ var SITE4 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
63298
+ var usd3 = (v) => {
63299
+ const n2 = Number(v);
63300
+ if (Number.isInteger(n2)) return `$${n2}`;
63301
+ const [whole, frac = ""] = n2.toFixed(6).replace(/0+$/, "").split(".");
63302
+ return `$${whole}.${frac.padEnd(2, "0")}`;
63303
+ };
63304
+ var family = (rung) => {
63305
+ const base = rung.replace(/-?(month|year)$/, "");
63306
+ return base === "" ? "Starter" : base.charAt(0).toUpperCase() + base.slice(1);
63307
+ };
63308
+ function emailSlice(body) {
63309
+ const out = {
63310
+ ...body,
63311
+ products: (body.products ?? []).filter((p) => p.id === "inbox"),
63312
+ rungs: (body.rungs ?? []).filter((r) => r.product === "inbox"),
63313
+ prices: (body.prices ?? []).filter((p) => p.product === "inbox")
63314
+ };
63315
+ for (const k of ["booth", "phoneUsage", "voices", "operator", "countries"]) {
63316
+ delete out[k];
63317
+ }
63318
+ return out;
63319
+ }
63320
+ async function emailPricing(opts) {
63321
+ const res = await fetch(`${SITE4}/api/account/catalog`, { headers: { accept: "application/json" } });
63322
+ if (!res.ok) throw new Error(`email catalog: HTTP ${res.status}`);
63323
+ const body = await res.json();
63324
+ const slice = emailSlice(body);
63325
+ const product = slice.products?.[0];
63326
+ if (opts.json) {
63327
+ process.stdout.write(JSON.stringify(slice, null, 2) + "\n");
63328
+ if (!product || product.available === false) process.exitCode = 1;
63329
+ return;
63330
+ }
63331
+ if (!product || product.available === false) {
63332
+ process.stdout.write(` ${import_picocolors6.default.dim(product?.note || product?.brief || "Inboxes are not on sale right now.")}
63333
+ `);
63334
+ process.exitCode = 1;
63335
+ return;
63336
+ }
63337
+ process.stdout.write(`
63338
+ ${import_picocolors6.default.bold("EMAIL")} ${import_picocolors6.default.dim(product.brief || "an inbox on your wallet")}
63339
+
63340
+ `);
63341
+ const freeInboxes = slice.payg?.inboxes;
63342
+ if (freeInboxes) {
63343
+ const at = product.domain ? ` @ ${product.domain}` : "";
63344
+ process.stdout.write(
63345
+ ` ${import_picocolors6.default.bold("free".padEnd(11))} ${import_picocolors6.default.cyan("$0".padStart(4))}${"".padEnd(11)} ${import_picocolors6.default.dim(`${freeInboxes} inbox${freeInboxes === 1 ? "" : "es"}${at}, behind a funded balance`)}
63346
+ `
63347
+ );
63348
+ }
63349
+ const plans = slice.prices ?? [];
63350
+ const families = [];
63351
+ const byFamily = /* @__PURE__ */ new Map();
63352
+ for (const p of plans) {
63353
+ const f2 = family(p.rung);
63354
+ if (!byFamily.has(f2)) {
63355
+ byFamily.set(f2, []);
63356
+ families.push(f2);
63357
+ }
63358
+ byFamily.get(f2).push(p);
63359
+ }
63360
+ for (const f2 of families) {
63361
+ const rows = byFamily.get(f2).sort((a, b2) => a.units - b2.units);
63362
+ const cells = rows.map((p) => `${import_picocolors6.default.cyan(usd3(p.priceUsd).padStart(4))}${import_picocolors6.default.dim(`/${p.units} days`.padEnd(10))}`).join(" ");
63363
+ const lead = rows[0];
63364
+ const cap = [
63365
+ lead.inboxes ? `${lead.inboxes} inbox${lead.inboxes === 1 ? "" : "es"}` : "",
63366
+ lead.sendsPerDay ? `${lead.sendsPerDay} sends/day` : ""
63367
+ ].filter(Boolean).join(" \xB7 ");
63368
+ process.stdout.write(` ${import_picocolors6.default.bold(f2.padEnd(11))} ${cells} ${import_picocolors6.default.dim(cap)}
63369
+ `);
63370
+ }
63371
+ if (plans.length === 0) process.stdout.write(` ${import_picocolors6.default.dim("no plan rungs are priced right now")}
63372
+ `);
63373
+ const send2 = slice.sendOverflow?.priceUsd;
63374
+ const wait2 = body.phoneUsage?.waitCodeUsd;
63375
+ const meter = [
63376
+ send2 ? `send ${usd3(send2)}` : "",
63377
+ wait2 !== void 0 ? `wait-code ${Number(wait2) === 0 ? "free" : usd3(wait2)}` : ""
63378
+ ].filter(Boolean).join(" \xB7 ");
63379
+ if (meter) process.stdout.write(`
63380
+ ${import_picocolors6.default.dim(`usage, from the prepaid balance: ${meter}`)}
63381
+ `);
63382
+ process.stdout.write(` ${import_picocolors6.default.dim("receiving costs nothing; the plan sells inboxes and sends per day")}
63383
+ `);
63384
+ const bal = slice.balance;
63385
+ if (bal?.note) process.stdout.write(` ${import_picocolors6.default.dim(bal.note)}
63386
+ `);
63387
+ else if (bal?.minTopUpUsd) process.stdout.write(` ${import_picocolors6.default.dim(`top up any amount from ${usd3(bal.minTopUpUsd)}`)}
63388
+ `);
63389
+ const nets = [...new Set((plans[0]?.byNetwork ?? []).map((n2) => n2.network))];
63390
+ if (nets.length) process.stdout.write(`
63391
+ ${import_picocolors6.default.dim(`USDC on ${nets.join(", ")}`)}
63392
+
63393
+ `);
63394
+ else process.stdout.write("\n");
63395
+ }
63396
+ function emailDoor(first) {
63397
+ process.stdout.write(
63398
+ `
63399
+ ${first}, and this CLI has no signer yet.
63400
+ Do it from the wallet, one biometric: ${import_picocolors6.default.cyan(`${SITE4}/email`)}
63401
+ Prices from here: ${import_picocolors6.default.dim("agentgates email pricing")}
63402
+
63403
+ `
63404
+ );
63405
+ }
63406
+ async function emailCreate() {
63407
+ emailDoor("An inbox is created under your wallet's own signature");
63408
+ }
63409
+ async function emailSend() {
63410
+ emailDoor("A send signs with your wallet and draws from its balance");
63411
+ }
63412
+
63413
+ // src/commands/passwords.ts
63414
+ var import_picocolors8 = __toESM(require_picocolors(), 1);
63415
+ import { readFileSync, writeFileSync } from "node:fs";
63416
+ import { randomBytes as randomBytes7 } from "node:crypto";
63417
+
63418
+ // src/commands/session.ts
63419
+ var import_picocolors7 = __toESM(require_picocolors(), 1);
63420
+
63154
63421
  // src/lib/session-bridge.ts
63155
63422
  import { createServer } from "node:http";
63156
63423
  import { randomBytes as randomBytes5 } from "node:crypto";
@@ -63185,12 +63452,12 @@ function readBody(req, limit = 4096) {
63185
63452
  req.on("error", reject);
63186
63453
  });
63187
63454
  }
63188
- function json(res, status3, body) {
63189
- res.writeHead(status3, { "content-type": "application/json", "cache-control": "no-store" });
63455
+ function json(res, status4, body) {
63456
+ res.writeHead(status4, { "content-type": "application/json", "cache-control": "no-store" });
63190
63457
  res.end(JSON.stringify(body));
63191
63458
  }
63192
- function html(res, status3, body) {
63193
- res.writeHead(status3, {
63459
+ function html(res, status4, body) {
63460
+ res.writeHead(status4, {
63194
63461
  "content-type": "text/html; charset=utf-8",
63195
63462
  "cache-control": "no-store",
63196
63463
  "referrer-policy": "no-referrer",
@@ -63362,9 +63629,9 @@ function handoffCode(code, port) {
63362
63629
  }
63363
63630
 
63364
63631
  // src/commands/session.ts
63365
- var jsonMode = (opts) => opts.json === true || !process.stdout.isTTY;
63366
- function refuse(opts, error, code = null) {
63367
- if (jsonMode(opts)) process.stdout.write(JSON.stringify({ ok: false, code, error }, null, 2) + "\n");
63632
+ var jsonMode2 = (opts) => opts.json === true || !process.stdout.isTTY;
63633
+ function refuse2(opts, error, code = null) {
63634
+ if (jsonMode2(opts)) process.stdout.write(JSON.stringify({ ok: false, code, error }, null, 2) + "\n");
63368
63635
  else process.stderr.write(` ${error}${code ? import_picocolors7.default.dim(` (${code})`) : ""}
63369
63636
  `);
63370
63637
  process.exit(1);
@@ -63382,10 +63649,10 @@ async function sessionOpen(opts) {
63382
63649
  try {
63383
63650
  keys2 = await requirePasswordsKey();
63384
63651
  } catch (err) {
63385
- return refuse(opts, err.message, "no_key");
63652
+ return refuse2(opts, err.message, "no_key");
63386
63653
  }
63387
63654
  const words7 = keys2.state.mnemonic;
63388
- 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");
63655
+ if (!words7) return refuse2(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");
63389
63656
  const address = keys2.wallet.address;
63390
63657
  try {
63391
63658
  await serveWordsOnce({
@@ -63393,7 +63660,7 @@ async function sessionOpen(opts) {
63393
63660
  address,
63394
63661
  waitMs,
63395
63662
  onUrl: (url, port) => {
63396
- if (jsonMode(opts)) {
63663
+ if (jsonMode2(opts)) {
63397
63664
  process.stdout.write(JSON.stringify({ ok: true, status: "waiting", url, port, address, waitSeconds: waitMs / 1e3 }) + "\n");
63398
63665
  } else {
63399
63666
  process.stdout.write(`
@@ -63408,12 +63675,12 @@ async function sessionOpen(opts) {
63408
63675
  });
63409
63676
  }
63410
63677
  });
63411
- if (jsonMode(opts)) process.stdout.write(JSON.stringify({ ok: true, status: "handed", address }) + "\n");
63678
+ if (jsonMode2(opts)) process.stdout.write(JSON.stringify({ ok: true, status: "handed", address }) + "\n");
63412
63679
  else process.stdout.write(` ${import_picocolors7.default.green("\u2713")} handed over; the browser is this account now.
63413
63680
 
63414
63681
  `);
63415
63682
  } catch (err) {
63416
- return refuse(opts, err.message, "not_taken");
63683
+ return refuse2(opts, err.message, "not_taken");
63417
63684
  }
63418
63685
  }
63419
63686
  async function sessionReceive(opts) {
@@ -63423,7 +63690,7 @@ async function sessionReceive(opts) {
63423
63690
  waitMs,
63424
63691
  onCode: (code, port) => {
63425
63692
  const typed = handoffCode(code, port);
63426
- if (jsonMode(opts)) {
63693
+ if (jsonMode2(opts)) {
63427
63694
  process.stdout.write(JSON.stringify({ ok: true, status: "waiting", code: typed, port, waitSeconds: waitMs / 1e3 }) + "\n");
63428
63695
  } else {
63429
63696
  process.stdout.write(`
@@ -63437,14 +63704,14 @@ async function sessionReceive(opts) {
63437
63704
  }
63438
63705
  });
63439
63706
  const { state } = await importPasswordsSeed({ seed: words7, replace: opts.replace === true });
63440
- if (jsonMode(opts)) process.stdout.write(JSON.stringify({ ok: true, status: "received", address: state.address, path: passwordsKeyPath() }) + "\n");
63707
+ if (jsonMode2(opts)) process.stdout.write(JSON.stringify({ ok: true, status: "received", address: state.address, path: passwordsKeyPath() }) + "\n");
63441
63708
  else process.stdout.write(` ${import_picocolors7.default.green("\u2713")} this CLI is ${import_picocolors7.default.bold(state.address)} now
63442
63709
  ${import_picocolors7.default.dim(passwordsKeyPath())}
63443
63710
 
63444
63711
  `);
63445
63712
  } catch (err) {
63446
63713
  const message = err.message;
63447
- return refuse(opts, message, /already exists/.test(message) ? "key_exists" : "not_received");
63714
+ return refuse2(opts, message, /already exists/.test(message) ? "key_exists" : "not_received");
63448
63715
  }
63449
63716
  }
63450
63717
 
@@ -63468,7 +63735,8 @@ var KDF_VERSIONS = Object.keys(KDF_SALTS).map(Number).sort((a, b2) => b2 - a);
63468
63735
  var VAULT_WALLET_MESSAGE_V1 = "Agentgates Passwords vault key v1\nagentgates.ai\nThis signature encrypts your stored passwords. Sign it only here.";
63469
63736
  var SECRET_KINDS = ["login", "api_key", "totp", "raw", "session", "oauth"];
63470
63737
  var CLI_SECRET_KINDS = ["login", "api_key", "totp", "raw"];
63471
- var USE_KINDS = ["header", "totp", "login"];
63738
+ var USE_KINDS = ["header", "totp", "login", "session", "reveal"];
63739
+ var ACTING_USES = ["header", "totp", "login"];
63472
63740
  var SECRET_ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
63473
63741
  var HOSTNAME_RE = /^(?=.{1,253}$)([a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,63}$/i;
63474
63742
  var MAX_HOSTS_PER_SECRET = 8;
@@ -63684,7 +63952,7 @@ function validatePermitRequest(owner, m, nowSeconds = Math.floor(Date.now() / 1e
63684
63952
  if (m.uses.length < 1 || m.uses.length > USE_KINDS.length) throw new PasswordsSealError("name at least one use");
63685
63953
  const seen = /* @__PURE__ */ new Set();
63686
63954
  for (const u of m.uses) {
63687
- if (!USE_KINDS.includes(u) || seen.has(u)) throw new PasswordsSealError("--uses takes distinct entries of login, totp, header");
63955
+ if (!USE_KINDS.includes(u) || seen.has(u)) throw new PasswordsSealError(`--uses takes distinct entries of ${USE_KINDS.join(", ")}`);
63688
63956
  seen.add(u);
63689
63957
  }
63690
63958
  if (!Number.isInteger(m.expiresAt) || m.expiresAt <= nowSeconds) throw new PasswordsSealError("that expiry has already passed");
@@ -63811,16 +64079,16 @@ function loginKeyLines(login2) {
63811
64079
  `;
63812
64080
  }
63813
64081
  var SITE5 = (process.env.AGENTGATES_ORIGIN || "https://agentgates.ai").replace(/\/$/, "");
63814
- var jsonMode2 = (opts) => opts.json === true || !process.stdout.isTTY;
63815
- function emit2(opts, data4, human) {
63816
- if (jsonMode2(opts)) {
64082
+ var jsonMode3 = (opts) => opts.json === true || !process.stdout.isTTY;
64083
+ function emit3(opts, data4, human) {
64084
+ if (jsonMode3(opts)) {
63817
64085
  process.stdout.write(JSON.stringify(data4, null, 2) + "\n");
63818
64086
  return;
63819
64087
  }
63820
64088
  human();
63821
64089
  }
63822
- function refuse2(opts, error, code, extra = {}) {
63823
- if (jsonMode2(opts)) {
64090
+ function refuse3(opts, error, code, extra = {}) {
64091
+ if (jsonMode3(opts)) {
63824
64092
  process.stdout.write(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
63825
64093
  } else {
63826
64094
  process.stderr.write(` ${error}${code ? import_picocolors8.default.dim(` (${code})`) : ""}
@@ -63828,10 +64096,10 @@ function refuse2(opts, error, code, extra = {}) {
63828
64096
  }
63829
64097
  process.exit(1);
63830
64098
  }
63831
- function failFrom(opts, err) {
63832
- if (err instanceof WireError) return refuse2(opts, err.message, err.code, { status: err.status });
63833
- if (err instanceof PasswordsSealError) return refuse2(opts, err.message, "refused");
63834
- return refuse2(opts, err.message ?? String(err), null);
64099
+ function failFrom2(opts, err) {
64100
+ if (err instanceof WireError) return refuse3(opts, err.message, err.code, { status: err.status });
64101
+ if (err instanceof PasswordsSealError) return refuse3(opts, err.message, "refused");
64102
+ return refuse3(opts, err.message ?? String(err), null);
63835
64103
  }
63836
64104
  var short = (addr) => `${addr.slice(0, 6)}\u2026${addr.slice(-4)}`;
63837
64105
  var splitList = (v) => (v ?? "").split(",").map((s) => s.trim()).filter(Boolean);
@@ -63843,6 +64111,17 @@ function parseUses(raw, dflt) {
63843
64111
  }
63844
64112
  return list;
63845
64113
  }
64114
+ function parseGets(raw) {
64115
+ const v = (raw ?? "session").trim().toLowerCase();
64116
+ if (v === "box" || v === "session" || v === "password") return v;
64117
+ throw new PasswordsSealError("--gets is one of session, password (or box: the acting uses alone)");
64118
+ }
64119
+ function withLevel(uses, gets) {
64120
+ const out = uses.filter((u) => u !== "session" && u !== "reveal");
64121
+ if (gets !== "box") out.push("session");
64122
+ if (gets === "password") out.push("reveal");
64123
+ return out;
64124
+ }
63846
64125
  function parseInt10(raw, name, dflt, min, max) {
63847
64126
  if (raw === void 0 || raw === "") return dflt;
63848
64127
  const n2 = Number(raw);
@@ -63872,7 +64151,7 @@ function passwordsSlice(body) {
63872
64151
  return out;
63873
64152
  }
63874
64153
  async function passwordsPricing(opts) {
63875
- const res = await fetch(`${SITE5}/api/identity/catalog`, { headers: { accept: "application/json" } });
64154
+ const res = await fetch(`${SITE5}/api/account/catalog`, { headers: { accept: "application/json" } });
63876
64155
  if (!res.ok) throw new Error(`passwords catalog: HTTP ${res.status}`);
63877
64156
  const body = await res.json();
63878
64157
  const slice = passwordsSlice(body);
@@ -63949,7 +64228,7 @@ async function passwordsInit(opts) {
63949
64228
  try {
63950
64229
  if (opts.import) {
63951
64230
  const { state: state2 } = await importPasswordsKey(opts.import, opts.replace === true);
63952
- emit2(opts, { ok: true, address: state2.address, created: false, imported: true, path: passwordsKeyPath() }, () => {
64231
+ emit3(opts, { ok: true, address: state2.address, created: false, imported: true, path: passwordsKeyPath() }, () => {
63953
64232
  process.stdout.write(`
63954
64233
  ${import_picocolors8.default.green("\u2713")} key imported: ${import_picocolors8.default.bold(state2.address)}
63955
64234
  ${import_picocolors8.default.dim(passwordsKeyPath())}
@@ -63961,7 +64240,7 @@ async function passwordsInit(opts) {
63961
64240
  if (opts.seed) {
63962
64241
  const brought = await importPasswordsSeed({ seed: opts.seed, replace: opts.replace === true });
63963
64242
  const login3 = await mintLoginKeyIfMissing(brought);
63964
- emit2(opts, { ok: true, address: brought.state.address, created: false, imported: true, words: SEED_WORDS, path: passwordsKeyPath(), ...loginKeyFields(login3) }, () => {
64243
+ emit3(opts, { ok: true, address: brought.state.address, created: false, imported: true, words: SEED_WORDS, path: passwordsKeyPath(), ...loginKeyFields(login3) }, () => {
63965
64244
  process.stdout.write(`
63966
64245
  ${import_picocolors8.default.green("\u2713")} twelve words taken: ${import_picocolors8.default.bold(brought.state.address)}
63967
64246
  ${import_picocolors8.default.dim(passwordsKeyPath())}
@@ -63972,7 +64251,7 @@ async function passwordsInit(opts) {
63972
64251
  if (opts.revealSeed) {
63973
64252
  const { state: state2 } = await requirePasswordsKey();
63974
64253
  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.");
63975
- emit2(opts, { ok: true, address: state2.address, seed: state2.mnemonic }, () => {
64254
+ emit3(opts, { ok: true, address: state2.address, seed: state2.mnemonic }, () => {
63976
64255
  process.stdout.write(`
63977
64256
  ${state2.mnemonic}
63978
64257
 
@@ -63985,7 +64264,7 @@ async function passwordsInit(opts) {
63985
64264
  const made = await loadOrCreatePasswordsKey();
63986
64265
  const { state, created, minted } = made;
63987
64266
  const login2 = await mintLoginKeyIfMissing(made);
63988
- emit2(opts, { ok: true, address: state.address, created, path: passwordsKeyPath(), ...minted ? { seed: minted.seed } : {}, ...loginKeyFields(login2) }, () => {
64267
+ emit3(opts, { ok: true, address: state.address, created, path: passwordsKeyPath(), ...minted ? { seed: minted.seed } : {}, ...loginKeyFields(login2) }, () => {
63989
64268
  process.stdout.write(
63990
64269
  `
63991
64270
  ${import_picocolors8.default.green("\u2713")} ${created ? "key minted" : "key already here"}: ${import_picocolors8.default.bold(state.address)}
@@ -64005,7 +64284,7 @@ async function passwordsInit(opts) {
64005
64284
  );
64006
64285
  });
64007
64286
  } catch (err) {
64008
- failFrom(opts, err);
64287
+ failFrom2(opts, err);
64009
64288
  }
64010
64289
  }
64011
64290
  async function passwordsAdd(opts) {
@@ -64047,7 +64326,7 @@ async function passwordsAdd(opts) {
64047
64326
  cvmBlob,
64048
64327
  cvmKeyId: att.keyId
64049
64328
  });
64050
- emit2(opts, { ok: true, id: row.id, label: row.label, kind: row.kind, hosts: row.hosts, username: row.username ?? null, owner: wallet.address }, () => {
64329
+ emit3(opts, { ok: true, id: row.id, label: row.label, kind: row.kind, hosts: row.hosts, username: row.username ?? null, owner: wallet.address }, () => {
64051
64330
  process.stdout.write(
64052
64331
  `
64053
64332
  ${import_picocolors8.default.green("\u2713")} stored ${import_picocolors8.default.bold(row.label)} for ${row.hosts.join(", ")}
@@ -64061,7 +64340,7 @@ async function passwordsAdd(opts) {
64061
64340
  );
64062
64341
  });
64063
64342
  } catch (err) {
64064
- failFrom(opts, err);
64343
+ failFrom2(opts, err);
64065
64344
  }
64066
64345
  }
64067
64346
  async function passwordsAllow(opts) {
@@ -64076,14 +64355,14 @@ async function passwordsAllow(opts) {
64076
64355
  secretIds,
64077
64356
  hosts: splitList(opts.hosts),
64078
64357
  usesPerDay: parseInt10(opts.perDay, "--per-day", 0, 0, 1e6),
64079
- uses: parseUses(opts.uses, [...USE_KINDS]),
64358
+ uses: withLevel(parseUses(opts.uses, [...ACTING_USES]), parseGets(opts.gets)),
64080
64359
  expiresAt: Math.floor(Date.now() / 1e3) + days * 86400,
64081
64360
  approveEachUse: opts.askMe === true
64082
64361
  };
64083
64362
  const self2 = agent.toLowerCase() === wallet.address.toLowerCase();
64084
64363
  const signed2 = await signPermit(wallet, request);
64085
64364
  const permit = await postPermit(wallet, signed2);
64086
- 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 }, () => {
64365
+ emit3(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 }, () => {
64087
64366
  process.stdout.write(
64088
64367
  `
64089
64368
  ${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)}
@@ -64093,14 +64372,14 @@ async function passwordsAllow(opts) {
64093
64372
  );
64094
64373
  });
64095
64374
  } catch (err) {
64096
- failFrom(opts, err);
64375
+ failFrom2(opts, err);
64097
64376
  }
64098
64377
  }
64099
64378
  async function passwordsList(opts) {
64100
64379
  try {
64101
64380
  const { wallet } = await requirePasswordsKey();
64102
64381
  const { passwords: passwords2, permitted } = await listRows(wallet);
64103
- emit2(opts, { ok: true, address: wallet.address, passwords: passwords2, permitted }, () => {
64382
+ emit3(opts, { ok: true, address: wallet.address, passwords: passwords2, permitted }, () => {
64104
64383
  process.stdout.write(`
64105
64384
  ${import_picocolors8.default.bold(short(wallet.address))}
64106
64385
 
@@ -64126,7 +64405,7 @@ async function passwordsList(opts) {
64126
64405
  process.stdout.write("\n");
64127
64406
  });
64128
64407
  } catch (err) {
64129
- failFrom(opts, err);
64408
+ failFrom2(opts, err);
64130
64409
  }
64131
64410
  }
64132
64411
  async function rowForUrl(wallet, url) {
@@ -64144,16 +64423,37 @@ async function rowForUrl(wallet, url) {
64144
64423
  if (lent) return lent.id;
64145
64424
  throw new PasswordsSealError(`no login this key holds or may use covers ${host2}; pass --row <id>, or add one`);
64146
64425
  }
64147
- function printUseAnswer(opts, status3, body) {
64148
- const data4 = { ok: body.ok === true, status: status3, ...body };
64149
- emit2(opts, data4, () => {
64150
- if (status3 === 200) {
64426
+ function printUseAnswer(opts, status4, body) {
64427
+ const data4 = { ok: body.ok === true, status: status4, ...body };
64428
+ const cookies = status4 === 200 && Array.isArray(body.result?.cookies) ? body.result.cookies : null;
64429
+ if (cookies && opts.cookiesOut) {
64430
+ writeFileSync(opts.cookiesOut, JSON.stringify(cookies, null, 2), { mode: 384 });
64431
+ data4.cookiesOut = opts.cookiesOut;
64432
+ }
64433
+ emit3(opts, data4, () => {
64434
+ if (status4 === 200) {
64151
64435
  const result = body.result ?? {};
64152
64436
  const code = typeof result.code === "string" ? result.code : "ok";
64153
64437
  const digest = typeof result.digest === "string" ? result.digest : "";
64154
64438
  process.stdout.write(`
64155
64439
  ${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}`) : ""}
64156
64440
  `);
64441
+ if (cookies) {
64442
+ process.stdout.write(` ${cookies.length} cookie${cookies.length === 1 ? "" : "s"} for ${import_picocolors8.default.bold(String(result.url ?? ""))}${opts.cookiesOut ? import_picocolors8.default.dim(` \u2192 ${opts.cookiesOut}`) : import_picocolors8.default.dim(" (--cookies-out <file> writes them; --json prints them)")}
64443
+
64444
+ `);
64445
+ return;
64446
+ }
64447
+ if (result.secret && typeof result.secret === "object") {
64448
+ process.stdout.write(` ${import_picocolors8.default.dim("the permit hands this key the secret itself; it is on your screen now")}
64449
+ `);
64450
+ for (const [k, v] of Object.entries(result.secret)) process.stdout.write(` ${import_picocolors8.default.dim(k.padEnd(10))} ${v}
64451
+ `);
64452
+ if (typeof result.username === "string" && result.username) process.stdout.write(` ${import_picocolors8.default.dim("username".padEnd(10))} ${result.username}
64453
+ `);
64454
+ process.stdout.write("\n");
64455
+ return;
64456
+ }
64157
64457
  if (digest) process.stdout.write(`
64158
64458
  ${digest.split("\n").map((l) => ` ${l}`).join("\n")}
64159
64459
  `);
@@ -64164,7 +64464,7 @@ ${digest.split("\n").map((l) => ` ${l}`).join("\n")}
64164
64464
  return;
64165
64465
  }
64166
64466
  process.stdout.write(`
64167
- ${body.error ?? `HTTP ${status3}`}${body.code ? import_picocolors8.default.dim(` (${body.code})`) : ""}
64467
+ ${body.error ?? `HTTP ${status4}`}${body.code ? import_picocolors8.default.dim(` (${body.code})`) : ""}
64168
64468
  ${body.useId ? ` ${import_picocolors8.default.dim("use")} ${body.useId}
64169
64469
  ` : ""}
64170
64470
  `);
@@ -64191,29 +64491,47 @@ async function passwordsUse(opts) {
64191
64491
  throw new PasswordsSealError("--steps-json is not JSON");
64192
64492
  }
64193
64493
  }
64194
- if (use !== "totp" && typeof request.url !== "string") throw new PasswordsSealError("--url is the https URL the use targets");
64494
+ if (use !== "totp" && use !== "reveal" && typeof request.url !== "string") throw new PasswordsSealError("--url is the https URL the use targets");
64195
64495
  const rowId = opts.row ?? await rowForUrl(wallet, request.url);
64196
64496
  const waitCap = opts.wait !== void 0 ? parseInt10(opts.wait, "--wait", 0, 0, 3600) : null;
64197
- let answer = await postUse(wallet, rowId, { use, request: use === "totp" && Object.keys(request).length === 0 ? void 0 : request });
64497
+ const firstBody = { use, request: use === "totp" && Object.keys(request).length === 0 ? void 0 : request };
64498
+ let lastBody = firstBody;
64499
+ let answer = await postUse(wallet, rowId, firstBody);
64198
64500
  const startedAt = Date.now();
64199
- while (answer.status === 202 && !opts.noWait) {
64501
+ const boxBudgetEnd = waitCap !== null ? startedAt + waitCap * 1e3 : startedAt + 24e4;
64502
+ while (!opts.noWait) {
64200
64503
  const body2 = answer.body ?? {};
64201
- if (!body2.useId) break;
64202
- const expiresAt = body2.expiresAt ? Date.parse(body2.expiresAt) : NaN;
64203
- const deadline = Math.min(
64204
- Number.isFinite(expiresAt) ? expiresAt : Date.now() + 6e5,
64205
- waitCap !== null ? startedAt + waitCap * 1e3 : Number.POSITIVE_INFINITY
64206
- );
64207
- if (Date.now() >= deadline) break;
64208
- if (!jsonMode2(opts)) process.stderr.write(` ${import_picocolors8.default.dim(body2.error ?? "waiting for the owner")}
64504
+ if (answer.status === 202) {
64505
+ if (!body2.useId) break;
64506
+ const expiresAt = body2.expiresAt ? Date.parse(body2.expiresAt) : NaN;
64507
+ const deadline = Math.min(
64508
+ Number.isFinite(expiresAt) ? expiresAt : Date.now() + 6e5,
64509
+ waitCap !== null ? startedAt + waitCap * 1e3 : Number.POSITIVE_INFINITY
64510
+ );
64511
+ if (Date.now() >= deadline) break;
64512
+ if (!jsonMode3(opts)) process.stderr.write(` ${import_picocolors8.default.dim(body2.error ?? "waiting for the owner")}
64209
64513
  `);
64210
- answer = await postUse(wallet, rowId, { use, request: use === "totp" && Object.keys(request).length === 0 ? void 0 : request, useId: body2.useId, wait: 25 });
64514
+ lastBody = { ...firstBody, useId: body2.useId, wait: 25 };
64515
+ answer = await postUse(wallet, rowId, lastBody);
64516
+ continue;
64517
+ }
64518
+ const named = body2.startingInSeconds ?? body2.retryInSeconds;
64519
+ if (answer.status === 503 && typeof named === "number") {
64520
+ const seconds2 = Math.min(120, Math.max(5, Math.ceil(named)));
64521
+ if (Date.now() + seconds2 * 1e3 > boxBudgetEnd) break;
64522
+ if (!jsonMode3(opts)) process.stderr.write(` ${import_picocolors8.default.dim(`${body2.error ?? "the box is not ready"}; trying again in ${seconds2}s`)}
64523
+ `);
64524
+ await new Promise((r) => setTimeout(r, seconds2 * 1e3));
64525
+ answer = await postUse(wallet, rowId, lastBody);
64526
+ continue;
64527
+ }
64528
+ break;
64211
64529
  }
64212
64530
  const body = answer.body ?? {};
64213
64531
  printUseAnswer(opts, answer.status, body);
64214
64532
  if (answer.status !== 200 && !(answer.status === 202 && opts.noWait)) process.exitCode = 1;
64215
64533
  } catch (err) {
64216
- failFrom(opts, err);
64534
+ failFrom2(opts, err);
64217
64535
  }
64218
64536
  }
64219
64537
  function joinPath() {
@@ -64227,7 +64545,7 @@ async function passwordsInvite(opts) {
64227
64545
  const { envelope: envelope2, signature } = decodeInviteFragment(hash2);
64228
64546
  if (inviteSigner(envelope2, signature) !== wallet.address.toLowerCase()) throw new PasswordsSealError("that invitation was not signed by this key");
64229
64547
  const out = await withdrawInvite(wallet, envelope2, signature);
64230
- emit2(opts, { ok: true, withdrawn: true, nonce: out.nonce }, () => {
64548
+ emit3(opts, { ok: true, withdrawn: true, nonce: out.nonce }, () => {
64231
64549
  process.stdout.write(`
64232
64550
  ${import_picocolors8.default.green("\u2713")} withdrawn; that link opens nothing now
64233
64551
 
@@ -64237,7 +64555,7 @@ async function passwordsInvite(opts) {
64237
64555
  }
64238
64556
  const minutes = parseInt10(opts.minutes, "--minutes", INVITE_DEFAULT_MINUTES, INVITE_MIN_MINUTES, INVITE_MAX_MINUTES);
64239
64557
  const days = parseInt10(opts.days, "--days", 30, 1, MAX_PERMIT_DAYS);
64240
- const uses = parseUses(opts.uses, [...USE_KINDS]);
64558
+ const uses = withLevel(parseUses(opts.uses, [...ACTING_USES]), parseGets(opts.gets));
64241
64559
  const { passwords: passwords2 } = await listRows(wallet);
64242
64560
  const wanted = opts.rows ? splitList(opts.rows) : passwords2.map((r) => r.id);
64243
64561
  if (wanted.length === 0) throw new PasswordsSealError("this key holds no logins to hand over; add one first");
@@ -64283,7 +64601,7 @@ async function passwordsInvite(opts) {
64283
64601
  };
64284
64602
  const inviteSignature = await signInvite(wallet, envelope);
64285
64603
  const link = `${siteOrigin()}${joinPath()}#${encodeInviteFragment(envelope, inviteSignature, secret)}`;
64286
- 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 }, () => {
64604
+ emit3(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 }, () => {
64287
64605
  process.stdout.write(
64288
64606
  `
64289
64607
  ${import_picocolors8.default.green("\u2713")} an invitation over ${rows.length} login${rows.length === 1 ? "" : "s"}, good for ${minutes} minutes
@@ -64298,7 +64616,7 @@ async function passwordsInvite(opts) {
64298
64616
  );
64299
64617
  });
64300
64618
  } catch (err) {
64301
- failFrom(opts, err);
64619
+ failFrom2(opts, err);
64302
64620
  }
64303
64621
  }
64304
64622
 
@@ -64306,12 +64624,12 @@ async function passwordsInvite(opts) {
64306
64624
  var import_picocolors9 = __toESM(require_picocolors(), 1);
64307
64625
 
64308
64626
  // src/lib/browser-wire.ts
64309
- var BROWSER_LANE = "/api/identity/browser";
64627
+ var BROWSER_LANE = "/api/browser";
64310
64628
  var SETTLED = /* @__PURE__ */ new Set(["done", "failed", "cancelled"]);
64311
64629
  async function readBrowserCatalog() {
64312
64630
  let res;
64313
64631
  try {
64314
- res = await fetch(`${siteOrigin()}/api/identity/catalog`, { headers: { accept: "application/json", "user-agent": CLI_USER_AGENT } });
64632
+ res = await fetch(`${siteOrigin()}/api/account/catalog`, { headers: { accept: "application/json", "user-agent": CLI_USER_AGENT } });
64315
64633
  } catch (err) {
64316
64634
  throw new WireError(0, "network_error", `could not reach ${siteOrigin()}: ${err.message}`, null);
64317
64635
  }
@@ -64323,7 +64641,7 @@ async function readBrowserCatalog() {
64323
64641
  networks: body.payment?.networks ?? []
64324
64642
  };
64325
64643
  }
64326
- function expect(answer, what) {
64644
+ function expect2(answer, what) {
64327
64645
  if (answer.status >= 200 && answer.status < 300 && answer.body) return answer.body;
64328
64646
  const body = answer.body ?? null;
64329
64647
  const sentence = typeof body?.error === "string" ? body.error : answer.text.slice(0, 300) || `${what}: HTTP ${answer.status}`;
@@ -64335,33 +64653,34 @@ async function postTask(wallet, args) {
64335
64653
  if (args.hosts?.length) body.hosts = args.hosts;
64336
64654
  if (typeof args.maxSteps === "number") body.maxSteps = args.maxSteps;
64337
64655
  if (typeof args.maxSeconds === "number") body.maxSeconds = args.maxSeconds;
64656
+ if (args.cookies?.length) body.cookies = args.cookies;
64338
64657
  const answer = await signedFetch(wallet, "POST", `${BROWSER_LANE}/tasks`, body);
64339
- return expect(answer, "task").task;
64658
+ return expect2(answer, "task").task;
64340
64659
  }
64341
64660
  async function listTasks(wallet) {
64342
64661
  const answer = await signedFetch(wallet, "GET", `${BROWSER_LANE}/tasks`);
64343
- return expect(answer, "tasks").tasks ?? [];
64662
+ return expect2(answer, "tasks").tasks ?? [];
64344
64663
  }
64345
64664
  async function readTask(wallet, id2) {
64346
64665
  const answer = await signedFetch(wallet, "GET", `${BROWSER_LANE}/tasks/${encodeURIComponent(id2)}`);
64347
- return expect(answer, "task").task;
64666
+ return expect2(answer, "task").task;
64348
64667
  }
64349
64668
  async function readIdentityBalance(wallet) {
64350
64669
  const answer = await signedFetch(
64351
64670
  wallet,
64352
64671
  "GET",
64353
- `${LANE}/credits`
64672
+ lanePath(`/credits`)
64354
64673
  );
64355
- const body = expect(answer, "balance");
64674
+ const body = expect2(answer, "balance");
64356
64675
  return { balance: body.balance ?? null, entries: body.entries ?? [], rungsUsd: body.rungsUsd ?? [] };
64357
64676
  }
64358
64677
  async function readDepositAddress(wallet) {
64359
- const answer = await signedFetch(wallet, "GET", `${LANE}/deposit`);
64678
+ const answer = await signedFetch(wallet, "GET", lanePath(`/deposit`));
64360
64679
  if (answer.status === 503) {
64361
64680
  const b2 = answer.body ?? {};
64362
64681
  return { deposit: null, dark: typeof b2.error === "string" ? b2.error : "deposit addresses are not open yet on this deployment" };
64363
64682
  }
64364
- const body = expect(answer, "deposit address");
64683
+ const body = expect2(answer, "deposit address");
64365
64684
  const payToAll = Array.isArray(body.payToAll) ? body.payToAll : [];
64366
64685
  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 }));
64367
64686
  if (typeof body.address !== "string" || chains.length === 0) throw new WireError(answer.status, "bad_wire", "the deposit address could not be read", answer.body);
@@ -64376,13 +64695,13 @@ async function readDepositAddress(wallet) {
64376
64695
  };
64377
64696
  }
64378
64697
  async function scanDeposit(wallet) {
64379
- const answer = await signedFetch(wallet, "POST", `${LANE}/deposit`, { scan: true });
64380
- const body = answer.status === 429 ? answer.body ?? {} : expect(answer, "scan");
64698
+ const answer = await signedFetch(wallet, "POST", lanePath(`/deposit`), { scan: true });
64699
+ const body = answer.status === 429 ? answer.body ?? {} : expect2(answer, "scan");
64381
64700
  return { scanned: body.scanned === true, credited: typeof body.credited === "number" ? body.credited : 0, balance: body.balance ?? null };
64382
64701
  }
64383
64702
  async function cancelTask(wallet, id2) {
64384
64703
  const answer = await signedFetch(wallet, "POST", `${BROWSER_LANE}/tasks/${encodeURIComponent(id2)}/cancel`);
64385
- return expect(answer, "cancel").task;
64704
+ return expect2(answer, "cancel").task;
64386
64705
  }
64387
64706
  async function waitForTask(wallet, id2, { maxSeconds = 900, everyMs = 5e3, onTick } = {}) {
64388
64707
  const until = Date.now() + maxSeconds * 1e3;
@@ -64395,16 +64714,16 @@ async function waitForTask(wallet, id2, { maxSeconds = 900, everyMs = 5e3, onTic
64395
64714
  }
64396
64715
 
64397
64716
  // src/commands/browser.ts
64398
- var jsonMode3 = (opts) => opts.json === true || !process.stdout.isTTY;
64399
- function emit3(opts, data4, human) {
64400
- if (jsonMode3(opts)) {
64717
+ var jsonMode4 = (opts) => opts.json === true || !process.stdout.isTTY;
64718
+ function emit4(opts, data4, human) {
64719
+ if (jsonMode4(opts)) {
64401
64720
  process.stdout.write(JSON.stringify(data4, null, 2) + "\n");
64402
64721
  return;
64403
64722
  }
64404
64723
  human();
64405
64724
  }
64406
- function refuse3(opts, error, code, extra = {}) {
64407
- if (jsonMode3(opts)) {
64725
+ function refuse4(opts, error, code, extra = {}) {
64726
+ if (jsonMode4(opts)) {
64408
64727
  process.stdout.write(JSON.stringify({ ok: false, code, error, ...extra }, null, 2) + "\n");
64409
64728
  } else {
64410
64729
  process.stderr.write(` ${error}${code ? import_picocolors9.default.dim(` (${code})`) : ""}
@@ -64412,9 +64731,9 @@ function refuse3(opts, error, code, extra = {}) {
64412
64731
  }
64413
64732
  process.exit(1);
64414
64733
  }
64415
- function failFrom2(opts, err) {
64416
- if (err instanceof WireError) return refuse3(opts, err.message, err.code, { status: err.status });
64417
- return refuse3(opts, err.message ?? String(err), null);
64734
+ function failFrom3(opts, err) {
64735
+ if (err instanceof WireError) return refuse4(opts, err.message, err.code, { status: err.status });
64736
+ return refuse4(opts, err.message ?? String(err), null);
64418
64737
  }
64419
64738
  var usd5 = (v) => {
64420
64739
  const n2 = Number(v);
@@ -64429,22 +64748,22 @@ var host = (url) => {
64429
64748
  return url;
64430
64749
  }
64431
64750
  };
64432
- var when = (iso) => iso ? iso.replace("T", " ").slice(0, 16) : "";
64433
- var STATUS_COLOR = {
64751
+ var when2 = (iso) => iso ? iso.replace("T", " ").slice(0, 16) : "";
64752
+ var STATUS_COLOR2 = {
64434
64753
  queued: import_picocolors9.default.dim,
64435
64754
  running: import_picocolors9.default.cyan,
64436
64755
  done: import_picocolors9.default.green,
64437
64756
  failed: import_picocolors9.default.red,
64438
64757
  cancelled: import_picocolors9.default.dim
64439
64758
  };
64440
- var status = (s) => (STATUS_COLOR[s] ?? import_picocolors9.default.dim)(s.padEnd(9));
64759
+ var status2 = (s) => (STATUS_COLOR2[s] ?? import_picocolors9.default.dim)(s.padEnd(9));
64441
64760
  function siteUrl(raw) {
64442
64761
  const t = raw.trim();
64443
64762
  return /^[a-z][a-z0-9+.-]*:\/\//i.test(t) ? t : `https://${t}`;
64444
64763
  }
64445
64764
  function printTask(t, full) {
64446
64765
  process.stdout.write(`
64447
- ${status(t.status)} ${import_picocolors9.default.bold(t.id)} ${import_picocolors9.default.dim(host(t.url))} ${import_picocolors9.default.dim(`${t.stepsRun}/${t.maxSteps} steps`)}
64766
+ ${status2(t.status)} ${import_picocolors9.default.bold(t.id)} ${import_picocolors9.default.dim(host(t.url))} ${import_picocolors9.default.dim(`${t.stepsRun}/${t.maxSteps} steps`)}
64448
64767
  `);
64449
64768
  process.stdout.write(` ${t.goal}
64450
64769
  `);
@@ -64484,7 +64803,7 @@ function printTask(t, full) {
64484
64803
  async function browserPricing(opts) {
64485
64804
  try {
64486
64805
  const { product, usage, networks } = await readBrowserCatalog();
64487
- emit3(opts, { ok: true, product, usage, networks }, () => {
64806
+ emit4(opts, { ok: true, product, usage, networks }, () => {
64488
64807
  process.stdout.write(`
64489
64808
  ${import_picocolors9.default.bold("BROWSER")} ${import_picocolors9.default.dim(product?.brief ?? "a site and a task in words; it browses, then answers")}
64490
64809
 
@@ -64509,7 +64828,7 @@ async function browserPricing(opts) {
64509
64828
  process.stdout.write("\n");
64510
64829
  });
64511
64830
  } catch (err) {
64512
- failFrom2(opts, err);
64831
+ failFrom3(opts, err);
64513
64832
  }
64514
64833
  }
64515
64834
  async function browserBalance(opts) {
@@ -64523,7 +64842,7 @@ async function browserBalance(opts) {
64523
64842
  scan = { scanned: out.scanned, credited: out.credited };
64524
64843
  if (out.credited > 0) balance2 = await readIdentityBalance(keys2.wallet);
64525
64844
  }
64526
- emit3(opts, { ok: true, wallet: keys2.wallet.address, via: lastAuthVia(), loginKeyRevoked: loginKeyWasRevoked(), balance: balance2.balance, rungsUsd: balance2.rungsUsd, deposit, ...dark ? { depositDark: dark } : {}, ...scan ? { scan } : {} }, () => {
64845
+ emit4(opts, { ok: true, wallet: keys2.wallet.address, via: lastAuthVia(), loginKeyRevoked: loginKeyWasRevoked(), balance: balance2.balance, rungsUsd: balance2.rungsUsd, deposit, ...dark ? { depositDark: dark } : {}, ...scan ? { scan } : {} }, () => {
64527
64846
  process.stdout.write(`
64528
64847
  ${import_picocolors9.default.bold("BALANCE")} ${import_picocolors9.default.dim(keys2.wallet.address)}
64529
64848
 
@@ -64550,27 +64869,63 @@ async function browserBalance(opts) {
64550
64869
  } else {
64551
64870
  process.stdout.write(` ${import_picocolors9.default.dim(dark ?? "deposit addresses are not open yet")}
64552
64871
  `);
64553
- 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`)}
64872
+ if (balance2.rungsUsd.length) process.stdout.write(` ${import_picocolors9.default.dim(`top up over x402: POST /api/account/balance with {"amountUsd": ${balance2.rungsUsd[0]}} from a wallet that holds USDC`)}
64554
64873
  `);
64555
64874
  }
64556
64875
  process.stdout.write("\n");
64557
64876
  });
64558
64877
  } catch (err) {
64559
- failFrom2(opts, err);
64878
+ failFrom3(opts, err);
64879
+ }
64880
+ }
64881
+ async function sessionForTask(wallet, rowId, url) {
64882
+ if (!/^[A-Za-z0-9_-]{1,64}$/.test(rowId)) throw new WireError(400, "bad_request", "--login takes the saved password's row id (agentgates passwords list)", null);
64883
+ const body = { use: "session", request: { url } };
64884
+ let permitted = false;
64885
+ const startedAt = Date.now();
64886
+ for (; ; ) {
64887
+ const answer = await postUse(wallet, rowId, body);
64888
+ const b2 = answer.body ?? {};
64889
+ if (answer.status === 200) {
64890
+ const result = b2.result ?? {};
64891
+ if (result.code !== "ok" || !Array.isArray(result.cookies) || result.cookies.length === 0) {
64892
+ throw new WireError(200, result.code ?? "login_failed", result.error ?? `the login did not land (${result.code ?? "no answer"})`, answer.body);
64893
+ }
64894
+ return result.cookies;
64895
+ }
64896
+ if (answer.status === 202) {
64897
+ throw new WireError(202, "approval_pending", "this saved password asks you before each use; approve it on the Passwords board, or allow yourself without --ask-me", answer.body);
64898
+ }
64899
+ if (answer.status === 403 && (b2.code === "no_permit" || b2.code === "use_not_allowed") && !permitted) {
64900
+ const now = Math.floor(Date.now() / 1e3);
64901
+ const signed2 = await signPermit(wallet, { agent: wallet.address, secretIds: ["*"], hosts: [], usesPerDay: 0, uses: [...ACTING_USES, "session"], expiresAt: now + 30 * 86400, approveEachUse: false });
64902
+ await postPermit(wallet, signed2);
64903
+ permitted = true;
64904
+ continue;
64905
+ }
64906
+ const named = b2.startingInSeconds ?? b2.retryInSeconds;
64907
+ if (answer.status === 503 && typeof named === "number" && Date.now() - startedAt < 24e4) {
64908
+ await new Promise((r) => setTimeout(r, Math.min(120, Math.max(5, Math.ceil(named))) * 1e3));
64909
+ continue;
64910
+ }
64911
+ throw new WireError(answer.status, b2.code ?? null, b2.error ?? `the session use answered ${answer.status}`, answer.body);
64560
64912
  }
64561
64913
  }
64562
64914
  async function browserRun(url, opts) {
64563
64915
  const goal = (opts.task ?? "").trim();
64564
- if (!goal) return refuse3(opts, 'say what the browser agent should do: --task "<words>"', "bad_request");
64916
+ if (!goal) return refuse4(opts, 'say what the browser agent should do: --task "<words>"', "bad_request");
64565
64917
  const maxSteps = opts.steps !== void 0 ? Number(opts.steps) : void 0;
64566
- if (maxSteps !== void 0 && !Number.isInteger(maxSteps)) return refuse3(opts, "--steps must be a whole number", "bad_request");
64918
+ if (maxSteps !== void 0 && !Number.isInteger(maxSteps)) return refuse4(opts, "--steps must be a whole number", "bad_request");
64567
64919
  const maxSeconds = opts.seconds !== void 0 ? Number(opts.seconds) : void 0;
64568
- if (maxSeconds !== void 0 && !Number.isInteger(maxSeconds)) return refuse3(opts, "--seconds must be a whole number", "bad_request");
64920
+ if (maxSeconds !== void 0 && !Number.isInteger(maxSeconds)) return refuse4(opts, "--seconds must be a whole number", "bad_request");
64569
64921
  try {
64570
64922
  const keys2 = await requirePasswordsKey();
64571
- const task = await postTask(keys2.wallet, { url: siteUrl(url), goal, hosts: opts.host, maxSteps, maxSeconds });
64923
+ const cookies = opts.login ? await sessionForTask(keys2.wallet, opts.login.trim(), siteUrl(url)) : void 0;
64924
+ if (cookies && !jsonMode4(opts)) process.stderr.write(` ${import_picocolors9.default.dim(`signed in with the saved password: ${cookies.length} cookie${cookies.length === 1 ? "" : "s"} ride the task`)}
64925
+ `);
64926
+ const task = await postTask(keys2.wallet, { url: siteUrl(url), goal, hosts: opts.host, maxSteps, maxSeconds, cookies });
64572
64927
  if (!opts.wait) {
64573
- emit3(opts, { ok: true, task }, () => {
64928
+ emit4(opts, { ok: true, task }, () => {
64574
64929
  printTask(task, false);
64575
64930
  process.stdout.write(` ${import_picocolors9.default.dim(`read it back: agentgates browser task ${task.id} --wait`)}
64576
64931
 
@@ -64583,13 +64938,13 @@ async function browserRun(url, opts) {
64583
64938
  const settled = await waitForTask(keys2.wallet, task.id, {
64584
64939
  maxSeconds: waitSeconds,
64585
64940
  onTick: (t) => {
64586
- if (jsonMode3(opts) || t.status === lastStatus) return;
64941
+ if (jsonMode4(opts) || t.status === lastStatus) return;
64587
64942
  lastStatus = t.status;
64588
64943
  process.stderr.write(` ${import_picocolors9.default.dim(`${t.status}${t.status === "running" ? ` \xB7 ${t.stepsRun} steps` : ""}`)}
64589
64944
  `);
64590
64945
  }
64591
64946
  });
64592
- emit3(opts, { ok: SETTLED.has(settled.status), task: settled }, () => {
64947
+ emit4(opts, { ok: SETTLED.has(settled.status), task: settled }, () => {
64593
64948
  printTask(settled, true);
64594
64949
  if (!SETTLED.has(settled.status)) process.stdout.write(` ${import_picocolors9.default.dim(`still ${settled.status}; read it later: agentgates browser task ${settled.id} --wait`)}
64595
64950
 
@@ -64597,14 +64952,14 @@ async function browserRun(url, opts) {
64597
64952
  });
64598
64953
  if (settled.status === "failed") process.exitCode = 1;
64599
64954
  } catch (err) {
64600
- failFrom2(opts, err);
64955
+ failFrom3(opts, err);
64601
64956
  }
64602
64957
  }
64603
64958
  async function browserTasks(opts) {
64604
64959
  try {
64605
64960
  const keys2 = await requirePasswordsKey();
64606
64961
  const tasks = await listTasks(keys2.wallet);
64607
- emit3(opts, { ok: true, wallet: keys2.wallet.address, tasks }, () => {
64962
+ emit4(opts, { ok: true, wallet: keys2.wallet.address, tasks }, () => {
64608
64963
  process.stdout.write(`
64609
64964
  ${import_picocolors9.default.bold("YOUR TASKS")} ${import_picocolors9.default.dim(keys2.wallet.address)}
64610
64965
 
@@ -64617,7 +64972,7 @@ async function browserTasks(opts) {
64617
64972
  }
64618
64973
  for (const t of tasks) {
64619
64974
  const money = t.status === "done" ? usd5(t.chargedUsd) : t.status === "queued" || t.status === "running" ? `${usd5(t.reservedUsd)} reserved` : "";
64620
- process.stdout.write(` ${status(t.status)} ${t.id} ${import_picocolors9.default.dim(host(t.url).padEnd(24))} ${import_picocolors9.default.dim(`${t.stepsRun}/${t.maxSteps}`.padStart(6))} ${import_picocolors9.default.dim(money.padEnd(16))} ${import_picocolors9.default.dim(when(t.createdAt))}
64975
+ process.stdout.write(` ${status2(t.status)} ${t.id} ${import_picocolors9.default.dim(host(t.url).padEnd(24))} ${import_picocolors9.default.dim(`${t.stepsRun}/${t.maxSteps}`.padStart(6))} ${import_picocolors9.default.dim(money.padEnd(16))} ${import_picocolors9.default.dim(when2(t.createdAt))}
64621
64976
  `);
64622
64977
  process.stdout.write(` ${t.goal.length > 90 ? `${t.goal.slice(0, 89)}\u2026` : t.goal}
64623
64978
  `);
@@ -64625,7 +64980,7 @@ async function browserTasks(opts) {
64625
64980
  process.stdout.write("\n");
64626
64981
  });
64627
64982
  } catch (err) {
64628
- failFrom2(opts, err);
64983
+ failFrom3(opts, err);
64629
64984
  }
64630
64985
  }
64631
64986
  async function browserTask(id2, opts) {
@@ -64633,19 +64988,19 @@ async function browserTask(id2, opts) {
64633
64988
  const keys2 = await requirePasswordsKey();
64634
64989
  if (opts.cancel) {
64635
64990
  const task2 = await cancelTask(keys2.wallet, id2);
64636
- emit3(opts, { ok: true, task: task2 }, () => printTask(task2, false));
64991
+ emit4(opts, { ok: true, task: task2 }, () => printTask(task2, false));
64637
64992
  return;
64638
64993
  }
64639
64994
  const task = opts.wait ? await waitForTask(keys2.wallet, id2, {
64640
64995
  maxSeconds: typeof opts.wait === "string" ? Math.max(5, Number(opts.wait) || 0) : 900,
64641
64996
  onTick: (t) => {
64642
- if (!jsonMode3(opts) && !SETTLED.has(t.status)) process.stderr.write(` ${import_picocolors9.default.dim(`${t.status} \xB7 ${t.stepsRun} steps`)}
64997
+ if (!jsonMode4(opts) && !SETTLED.has(t.status)) process.stderr.write(` ${import_picocolors9.default.dim(`${t.status} \xB7 ${t.stepsRun} steps`)}
64643
64998
  `);
64644
64999
  }
64645
65000
  }) : await readTask(keys2.wallet, id2);
64646
- emit3(opts, { ok: true, task }, () => printTask(task, true));
65001
+ emit4(opts, { ok: true, task }, () => printTask(task, true));
64647
65002
  } catch (err) {
64648
- failFrom2(opts, err);
65003
+ failFrom3(opts, err);
64649
65004
  }
64650
65005
  }
64651
65006
 
@@ -64710,20 +65065,20 @@ function installedVersionAt(place) {
64710
65065
 
64711
65066
  // src/commands/update.ts
64712
65067
  var import_picocolors10 = __toESM(require_picocolors(), 1);
64713
- var jsonMode4 = (opts) => opts.json === true || !process.stdout.isTTY;
65068
+ var jsonMode5 = (opts) => opts.json === true || !process.stdout.isTTY;
64714
65069
  async function update(opts = {}) {
64715
65070
  const latest = await fetchLatest();
64716
65071
  const place = installPlace();
64717
65072
  const stale = !!latest && olderThan(LOCAL_VERSION, latest);
64718
65073
  const base = { ok: true, package: PKG, current: LOCAL_VERSION, latest, stale, runsFrom: place.kind, ...place.kind === "home" ? { home: place.home } : place.kind === "checkout" ? { dir: place.dir } : {} };
64719
65074
  if (!latest) {
64720
- if (jsonMode4(opts)) process.stdout.write(JSON.stringify({ ...base, ok: false, code: "registry_unreachable", error: "npm's registry did not answer; try again in a moment" }, null, 2) + "\n");
65075
+ if (jsonMode5(opts)) process.stdout.write(JSON.stringify({ ...base, ok: false, code: "registry_unreachable", error: "npm's registry did not answer; try again in a moment" }, null, 2) + "\n");
64721
65076
  else process.stderr.write(` ${import_picocolors10.default.red("\u2715")} npm's registry did not answer; try again in a moment
64722
65077
  `);
64723
65078
  process.exit(1);
64724
65079
  }
64725
65080
  if (opts.check || !stale) {
64726
- if (jsonMode4(opts)) process.stdout.write(JSON.stringify(base, null, 2) + "\n");
65081
+ if (jsonMode5(opts)) process.stdout.write(JSON.stringify(base, null, 2) + "\n");
64727
65082
  else if (stale) process.stdout.write(`
64728
65083
  ${import_picocolors10.default.yellow("\u2191")} ${latest} is out; this copy is ${LOCAL_VERSION}. ${import_picocolors10.default.dim("agentgates update \xB7 installs it")}
64729
65084
 
@@ -64736,7 +65091,7 @@ async function update(opts = {}) {
64736
65091
  }
64737
65092
  if (place.kind === "checkout") {
64738
65093
  const line = `cd ${place.dir} && git pull --ff-only && npm run build`;
64739
- if (jsonMode4(opts)) process.stdout.write(JSON.stringify({ ...base, ok: false, code: "checkout", line, error: "this copy runs from a repository checkout; pull it" }, null, 2) + "\n");
65094
+ if (jsonMode5(opts)) process.stdout.write(JSON.stringify({ ...base, ok: false, code: "checkout", line, error: "this copy runs from a repository checkout; pull it" }, null, 2) + "\n");
64740
65095
  else process.stdout.write(`
64741
65096
  this copy runs from a checkout at ${import_picocolors10.default.bold(place.dir)}; update it with
64742
65097
  ${import_picocolors10.default.cyan(line)}
@@ -64744,7 +65099,7 @@ async function update(opts = {}) {
64744
65099
  `);
64745
65100
  return;
64746
65101
  }
64747
- if (!jsonMode4(opts)) process.stdout.write(`
65102
+ if (!jsonMode5(opts)) process.stdout.write(`
64748
65103
  ${import_picocolors10.default.bold("UPDATE")} ${LOCAL_VERSION} \u2192 ${latest} ${import_picocolors10.default.dim(place.kind === "home" ? `into ${place.home}` : "the global npm install")}
64749
65104
  ${import_picocolors10.default.dim(`npm ${place.command.join(" ")}`)}
64750
65105
 
@@ -64752,7 +65107,7 @@ async function update(opts = {}) {
64752
65107
  const code = await runNpm(place.command);
64753
65108
  const now = installedVersionAt(place);
64754
65109
  const done = code === 0 && (place.kind !== "home" || now === latest);
64755
- if (jsonMode4(opts)) {
65110
+ if (jsonMode5(opts)) {
64756
65111
  process.stdout.write(JSON.stringify({ ...base, ok: done, code: done ? void 0 : "npm_failed", installed: now ?? void 0, exit: code }, null, 2) + "\n");
64757
65112
  } else if (done) {
64758
65113
  process.stdout.write(`
@@ -64819,9 +65174,9 @@ var MENU = {
64819
65174
  var LANES = {
64820
65175
  compute: { key: "compute", name: "virtual machines", docs: "/api/compute/docs" },
64821
65176
  inference: { key: "models", name: "inference", docs: "/api/inference/docs" },
64822
- phone: { key: "phone", name: "phone", docs: "/api/identity/docs/phone" },
64823
- email: { key: "email", name: "email", docs: "/api/identity/docs/email" },
64824
- passwords: { key: "passwords", name: "passwords", docs: "/api/identity/docs/passwords" }
65177
+ phone: { key: "phone", name: "phone", docs: "/api/account/docs/phone" },
65178
+ email: { key: "email", name: "email", docs: "/api/account/docs/email" },
65179
+ passwords: { key: "passwords", name: "passwords", docs: "/api/account/docs/passwords" }
64825
65180
  };
64826
65181
  var LANE_ORDER = ["compute", "inference", "phone", "email", "passwords"];
64827
65182
  function leadLane(lane) {
@@ -64912,11 +65267,11 @@ async function onboard(opts = {}) {
64912
65267
  `);
64913
65268
  put(` ${CREATORS_ORIGIN}/api/inference/docs ${import_picocolors11.default.dim("\xB7 the chat contract, x402 or Bearer")}
64914
65269
  `);
64915
- put(` ${CREATORS_ORIGIN}/api/identity/docs/phone ${import_picocolors11.default.dim("\xB7 the phone contract: numbers, texts, calls, the payphone")}
65270
+ put(` ${CREATORS_ORIGIN}/api/account/docs/phone ${import_picocolors11.default.dim("\xB7 the phone contract: numbers, texts, calls, the payphone")}
64916
65271
  `);
64917
- put(` ${CREATORS_ORIGIN}/api/identity/docs/email ${import_picocolors11.default.dim("\xB7 the email contract: inboxes, plans, sends, wait-code")}
65272
+ put(` ${CREATORS_ORIGIN}/api/account/docs/email ${import_picocolors11.default.dim("\xB7 the email contract: inboxes, plans, sends, wait-code")}
64918
65273
  `);
64919
- put(` ${CREATORS_ORIGIN}/api/identity/docs/passwords ${import_picocolors11.default.dim("\xB7 the passwords contract: store, permits, uses")}
65274
+ put(` ${CREATORS_ORIGIN}/api/account/docs/passwords ${import_picocolors11.default.dim("\xB7 the passwords contract: store, permits, uses")}
64920
65275
  `);
64921
65276
  put(` ${CREATORS_ORIGIN}/llms.txt ${import_picocolors11.default.dim("\xB7 the whole surface")}
64922
65277
 
@@ -65086,7 +65441,7 @@ function printNext(put) {
65086
65441
  // src/commands/keys.ts
65087
65442
  var import_picocolors12 = __toESM(require_picocolors(), 1);
65088
65443
  import { hostname as hostname2 } from "node:os";
65089
- function emit4(opts, data4, human) {
65444
+ function emit5(opts, data4, human) {
65090
65445
  if (opts.json || !process.stdout.isTTY) {
65091
65446
  process.stdout.write(`${JSON.stringify(data4)}
65092
65447
  `);
@@ -65134,7 +65489,7 @@ async function keysList(opts) {
65134
65489
  try {
65135
65490
  const keys2 = await requirePasswordsKey();
65136
65491
  const rows = await listLoginKeys(keys2.wallet);
65137
- emit4(opts, { ok: true, address: keys2.state.address, keys: rows, thisMachine: keys2.state.apiKeyPrefix ?? null }, () => printRows(rows, keys2.state.apiKeyPrefix ?? null));
65492
+ emit5(opts, { ok: true, address: keys2.state.address, keys: rows, thisMachine: keys2.state.apiKeyPrefix ?? null }, () => printRows(rows, keys2.state.apiKeyPrefix ?? null));
65138
65493
  } catch (err) {
65139
65494
  fail(opts, err);
65140
65495
  }
@@ -65145,14 +65500,14 @@ async function keysCreate(opts) {
65145
65500
  const name = (opts.name?.trim() || `cli ${hostname2()}`).slice(0, 64);
65146
65501
  const made = await createLoginKey(keys2.wallet, name);
65147
65502
  if (opts.keep) await saveLoginKey(keys2.state, { secret: made.key, prefix: made.created.prefix, name: made.created.name });
65148
- emit4(opts, { ok: true, key: made.key, created: made.created, kept: opts.keep === true }, () => {
65503
+ emit5(opts, { ok: true, key: made.key, created: made.created, kept: opts.keep === true }, () => {
65149
65504
  process.stdout.write(
65150
65505
  `
65151
65506
  ${import_picocolors12.default.green("\u2713")} login key minted: ${import_picocolors12.default.bold(made.created.name)}
65152
65507
 
65153
65508
  ${made.key}
65154
65509
 
65155
- ${import_picocolors12.default.dim("Shown once. Send it as Authorization: Bearer <key> on every /api/identity door; the words stay home.")}
65510
+ ${import_picocolors12.default.dim("Shown once. Send it as Authorization: Bearer <key> on every /api/account door; the words stay home.")}
65156
65511
  ` + (opts.keep ? ` ${import_picocolors12.default.dim("Kept in the key file: this machine sends it from now on.")}
65157
65512
 
65158
65513
  ` : ` ${import_picocolors12.default.dim("agentgates keys create --keep \xB7 would have made it this machine's")}
@@ -65172,7 +65527,7 @@ async function keysRevoke(id2, opts) {
65172
65527
  const out = await revokeLoginKey(keys2.wallet, id2);
65173
65528
  const wasMine = !!target && !!keys2.state.apiKeyPrefix && target.prefix === keys2.state.apiKeyPrefix;
65174
65529
  if (wasMine) await forgetLoginKey(keys2.state);
65175
- emit4(opts, { ok: true, revoked: id2, keys: out.keys, thisMachineDropped: wasMine }, () => {
65530
+ emit5(opts, { ok: true, revoked: id2, keys: out.keys, thisMachineDropped: wasMine }, () => {
65176
65531
  process.stdout.write(`
65177
65532
  ${import_picocolors12.default.green("\u2713")} revoked ${target ? import_picocolors12.default.bold(target.prefix) : id2}${wasMine ? import_picocolors12.default.dim(" (this machine signs with the words until keys create --keep)") : ""}
65178
65533
  `);
@@ -65247,16 +65602,16 @@ async function whoami(opts) {
65247
65602
  `));
65248
65603
  }
65249
65604
  const { profile, name: profileName } = resolved;
65250
- const jsonMode5 = opts.json === true;
65605
+ const jsonMode6 = opts.json === true;
65251
65606
  const outcome = await callWithAutoRelogin({
65252
65607
  profile,
65253
65608
  profileName,
65254
- jsonMode: jsonMode5,
65609
+ jsonMode: jsonMode6,
65255
65610
  ttyHeader: import_picocolors14.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
65256
65611
  fn: (bearer, origin) => apiFetch("/api/whoami", { bearer, origin })
65257
65612
  });
65258
65613
  if (outcome.kind === "auth_failed") {
65259
- if (jsonMode5) {
65614
+ if (jsonMode6) {
65260
65615
  process.stdout.write(
65261
65616
  JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
65262
65617
  );
@@ -65276,7 +65631,7 @@ async function whoami(opts) {
65276
65631
  throw err;
65277
65632
  }
65278
65633
  const me = outcome.result;
65279
- if (jsonMode5) {
65634
+ if (jsonMode6) {
65280
65635
  process.stdout.write(JSON.stringify(me, null, 2) + "\n");
65281
65636
  return;
65282
65637
  }
@@ -65480,7 +65835,7 @@ async function send(amount, asset, opts) {
65480
65835
  }
65481
65836
  const { profile, name: profileName } = resolved;
65482
65837
  const stdoutIsTty = process.stdout.isTTY === true;
65483
- const jsonMode5 = opts.json === true || !stdoutIsTty;
65838
+ const jsonMode6 = opts.json === true || !stdoutIsTty;
65484
65839
  const amountNumber = Number(amount);
65485
65840
  if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
65486
65841
  process.stderr.write(
@@ -65589,12 +65944,12 @@ async function send(amount, asset, opts) {
65589
65944
  try {
65590
65945
  activeProfile = await runLoginFlow({
65591
65946
  profile: profileName,
65592
- jsonMode: jsonMode5,
65947
+ jsonMode: jsonMode6,
65593
65948
  origin: activeProfile.mcpOrigin,
65594
65949
  ttyHeader: import_picocolors15.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026")
65595
65950
  });
65596
65951
  } catch (reloginErr) {
65597
- if (jsonMode5) {
65952
+ if (jsonMode6) {
65598
65953
  emitNdjson({
65599
65954
  ok: false,
65600
65955
  status: "auth_failed",
@@ -65617,7 +65972,7 @@ async function send(amount, asset, opts) {
65617
65972
  });
65618
65973
  } catch (retryErr) {
65619
65974
  if (retryErr instanceof ApiError) {
65620
- if (jsonMode5) {
65975
+ if (jsonMode6) {
65621
65976
  emitNdjson({
65622
65977
  ok: false,
65623
65978
  status: retryErr.status === 401 ? "auth_failed" : "propose_failed",
@@ -65635,7 +65990,7 @@ async function send(amount, asset, opts) {
65635
65990
  throw retryErr;
65636
65991
  }
65637
65992
  } else if (err instanceof ApiError) {
65638
- if (jsonMode5) {
65993
+ if (jsonMode6) {
65639
65994
  emitNdjson({
65640
65995
  ok: false,
65641
65996
  status: "propose_failed",
@@ -65652,7 +66007,7 @@ async function send(amount, asset, opts) {
65652
66007
  }
65653
66008
  }
65654
66009
  if (isBlocked(proposed)) {
65655
- if (jsonMode5) {
66010
+ if (jsonMode6) {
65656
66011
  const envelope = {
65657
66012
  ok: false,
65658
66013
  status: "blocked",
@@ -65716,7 +66071,7 @@ async function send(amount, asset, opts) {
65716
66071
  if (process.env.CI === "1" || process.env.CI === "true") return false;
65717
66072
  return true;
65718
66073
  })();
65719
- if (jsonMode5) {
66074
+ if (jsonMode6) {
65720
66075
  emitNdjson({
65721
66076
  ok: true,
65722
66077
  status: "proposed",
@@ -65748,7 +66103,7 @@ ${import_picocolors15.default.bold("Proposed.")} Open this URL to approve with b
65748
66103
  intervalMs: POLL_INTERVAL_MS,
65749
66104
  giveUpMs: POLL_GIVEUP_MS,
65750
66105
  onTick: (s) => {
65751
- if (jsonMode5) {
66106
+ if (jsonMode6) {
65752
66107
  emitNdjson({ status: s.status, intent_id: s.approval_id });
65753
66108
  } else {
65754
66109
  process.stdout.write(` ${describeStatus(s.status)}${import_picocolors15.default.dim("\u2026")}\r`);
@@ -65763,12 +66118,12 @@ ${import_picocolors15.default.bold("Proposed.")} Open this URL to approve with b
65763
66118
  try {
65764
66119
  activeProfile = await runLoginFlow({
65765
66120
  profile: profileName,
65766
- jsonMode: jsonMode5,
66121
+ jsonMode: jsonMode6,
65767
66122
  origin: activeProfile.mcpOrigin,
65768
66123
  ttyHeader: import_picocolors15.default.dim("Bearer expired mid-poll \u2014 re-pairing this terminal\u2026")
65769
66124
  });
65770
66125
  } catch (reloginErr) {
65771
- if (jsonMode5) {
66126
+ if (jsonMode6) {
65772
66127
  emitNdjson({
65773
66128
  ok: false,
65774
66129
  status: "auth_failed",
@@ -65786,7 +66141,7 @@ ${import_picocolors15.default.bold("Proposed.")} Open this URL to approve with b
65786
66141
  try {
65787
66142
  final = await runPoll(activeProfile);
65788
66143
  } catch (retryErr) {
65789
- if (jsonMode5) {
66144
+ if (jsonMode6) {
65790
66145
  emitNdjson({
65791
66146
  ok: false,
65792
66147
  status: retryErr instanceof ApiError && retryErr.status === 401 ? "auth_failed" : "poll_failed",
@@ -65802,7 +66157,7 @@ ${import_picocolors15.default.bold("Proposed.")} Open this URL to approve with b
65802
66157
  process.exit(1);
65803
66158
  }
65804
66159
  } else {
65805
- if (jsonMode5) {
66160
+ if (jsonMode6) {
65806
66161
  emitNdjson({
65807
66162
  ok: false,
65808
66163
  status: "poll_failed",
@@ -65819,7 +66174,7 @@ ${import_picocolors15.default.bold("Proposed.")} Open this URL to approve with b
65819
66174
  }
65820
66175
  }
65821
66176
  const explorer = final.tx_hash != null ? explorerUrl(final.chain_id, final.tx_hash) : null;
65822
- if (jsonMode5) {
66177
+ if (jsonMode6) {
65823
66178
  emitNdjson({
65824
66179
  ok: final.status === "mined",
65825
66180
  status: final.status,
@@ -65888,7 +66243,7 @@ function explorerUrl2(chainId, hash2) {
65888
66243
  return null;
65889
66244
  }
65890
66245
  }
65891
- async function status2(intentId, opts) {
66246
+ async function status3(intentId, opts) {
65892
66247
  if (!intentId || intentId.trim() === "") {
65893
66248
  process.stderr.write(import_picocolors16.default.red("\u2715 Missing intent id.\n"));
65894
66249
  process.exit(2);
@@ -65904,16 +66259,16 @@ async function status2(intentId, opts) {
65904
66259
  `));
65905
66260
  }
65906
66261
  const { profile, name: profileName } = resolved;
65907
- const jsonMode5 = opts.json === true;
66262
+ const jsonMode6 = opts.json === true;
65908
66263
  const outcome = await callWithAutoRelogin({
65909
66264
  profile,
65910
66265
  profileName,
65911
- jsonMode: jsonMode5,
66266
+ jsonMode: jsonMode6,
65912
66267
  ttyHeader: import_picocolors16.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
65913
66268
  fn: (bearer, origin) => fetchStatus({ intentId, bearer, origin })
65914
66269
  });
65915
66270
  if (outcome.kind === "auth_failed") {
65916
- if (jsonMode5) {
66271
+ if (jsonMode6) {
65917
66272
  process.stdout.write(
65918
66273
  JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
65919
66274
  );
@@ -65940,7 +66295,7 @@ async function status2(intentId, opts) {
65940
66295
  let snap = outcome.result;
65941
66296
  let activeProfile = outcome.profile;
65942
66297
  if (opts.watch && !isTerminalStatus(snap.status)) {
65943
- if (!jsonMode5) {
66298
+ if (!jsonMode6) {
65944
66299
  printSnap(snap);
65945
66300
  process.stdout.write(import_picocolors16.default.dim("Watching\u2026\n"));
65946
66301
  }
@@ -65952,7 +66307,7 @@ async function status2(intentId, opts) {
65952
66307
  intervalMs: 0,
65953
66308
  giveUpMs: WATCH_GIVEUP_MS,
65954
66309
  onTick: (s) => {
65955
- if (!jsonMode5) {
66310
+ if (!jsonMode6) {
65956
66311
  process.stdout.write(` ${import_picocolors16.default.dim("\u2192")} ${s.status}
65957
66312
  `);
65958
66313
  }
@@ -65966,12 +66321,12 @@ async function status2(intentId, opts) {
65966
66321
  try {
65967
66322
  activeProfile = await runLoginFlow({
65968
66323
  profile: profileName,
65969
- jsonMode: jsonMode5,
66324
+ jsonMode: jsonMode6,
65970
66325
  origin: activeProfile.mcpOrigin,
65971
66326
  ttyHeader: import_picocolors16.default.dim("Bearer expired mid-watch \u2014 re-pairing\u2026")
65972
66327
  });
65973
66328
  } catch (reloginErr) {
65974
- if (jsonMode5) {
66329
+ if (jsonMode6) {
65975
66330
  process.stdout.write(
65976
66331
  JSON.stringify({
65977
66332
  ok: false,
@@ -66000,14 +66355,14 @@ async function status2(intentId, opts) {
66000
66355
  process.exit(1);
66001
66356
  }
66002
66357
  }
66003
- if (jsonMode5) {
66358
+ if (jsonMode6) {
66004
66359
  process.stdout.write(JSON.stringify(final, null, 2) + "\n");
66005
66360
  } else {
66006
66361
  printSnap(final);
66007
66362
  }
66008
66363
  process.exit(final.status === "mined" ? 0 : 1);
66009
66364
  }
66010
- if (jsonMode5) {
66365
+ if (jsonMode6) {
66011
66366
  process.stdout.write(JSON.stringify(snap, null, 2) + "\n");
66012
66367
  process.exit(snap.status === "mined" ? 0 : 0);
66013
66368
  }
@@ -66099,16 +66454,16 @@ async function balance(opts) {
66099
66454
  }
66100
66455
  chainFilter = id2;
66101
66456
  }
66102
- const jsonMode5 = opts.json === true;
66457
+ const jsonMode6 = opts.json === true;
66103
66458
  const outcome = await callWithAutoRelogin({
66104
66459
  profile,
66105
66460
  profileName,
66106
- jsonMode: jsonMode5,
66461
+ jsonMode: jsonMode6,
66107
66462
  ttyHeader: import_picocolors17.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
66108
66463
  fn: (bearer, origin) => apiFetch("/api/balances", { bearer, origin })
66109
66464
  });
66110
66465
  if (outcome.kind === "auth_failed") {
66111
- if (jsonMode5) {
66466
+ if (jsonMode6) {
66112
66467
  process.stdout.write(
66113
66468
  JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
66114
66469
  );
@@ -66129,7 +66484,7 @@ async function balance(opts) {
66129
66484
  }
66130
66485
  const res = outcome.result;
66131
66486
  const filtered = chainFilter !== null ? res.chains.filter((c) => c.chainId === chainFilter) : res.chains;
66132
- if (jsonMode5) {
66487
+ if (jsonMode6) {
66133
66488
  process.stdout.write(
66134
66489
  JSON.stringify(
66135
66490
  chainFilter !== null ? { ...res, chains: filtered } : res,
@@ -66256,11 +66611,11 @@ async function history(opts) {
66256
66611
  }
66257
66612
  limit = n2;
66258
66613
  }
66259
- const jsonMode5 = opts.json === true;
66614
+ const jsonMode6 = opts.json === true;
66260
66615
  const outcome = await callWithAutoRelogin({
66261
66616
  profile,
66262
66617
  profileName,
66263
- jsonMode: jsonMode5,
66618
+ jsonMode: jsonMode6,
66264
66619
  ttyHeader: import_picocolors18.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
66265
66620
  fn: (bearer, origin) => apiFetch(
66266
66621
  `/api/history?limit=${encodeURIComponent(String(limit))}`,
@@ -66268,7 +66623,7 @@ async function history(opts) {
66268
66623
  )
66269
66624
  });
66270
66625
  if (outcome.kind === "auth_failed") {
66271
- if (jsonMode5) {
66626
+ if (jsonMode6) {
66272
66627
  process.stdout.write(
66273
66628
  JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
66274
66629
  );
@@ -66288,7 +66643,7 @@ async function history(opts) {
66288
66643
  throw err;
66289
66644
  }
66290
66645
  const res = outcome.result;
66291
- if (jsonMode5) {
66646
+ if (jsonMode6) {
66292
66647
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
66293
66648
  return;
66294
66649
  }
@@ -66376,7 +66731,7 @@ function chainIdLabel(id2) {
66376
66731
  return `chain ${id2}`;
66377
66732
  }
66378
66733
  }
66379
- function prettyType(activityType, status3) {
66734
+ function prettyType(activityType, status4) {
66380
66735
  const base = (() => {
66381
66736
  switch (activityType) {
66382
66737
  case "received":
@@ -66406,8 +66761,8 @@ function prettyType(activityType, status3) {
66406
66761
  return activityType;
66407
66762
  }
66408
66763
  })();
66409
- if (status3 && status3 !== "confirmed" && status3 !== "complete") {
66410
- return `${base} \xB7 ${status3}`;
66764
+ if (status4 && status4 !== "confirmed" && status4 !== "complete") {
66765
+ return `${base} \xB7 ${status4}`;
66411
66766
  }
66412
66767
  return base;
66413
66768
  }
@@ -66796,7 +67151,7 @@ async function swap(amount, fromAsset, opts) {
66796
67151
  }
66797
67152
  const { profile, name: profileName } = resolved;
66798
67153
  const stdoutIsTty = process.stdout.isTTY === true;
66799
- const jsonMode5 = opts.json === true || !stdoutIsTty;
67154
+ const jsonMode6 = opts.json === true || !stdoutIsTty;
66800
67155
  const amountNumber = Number(amount);
66801
67156
  if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
66802
67157
  failArg(`amount must be a positive number (got ${import_picocolors20.default.bold(amount)}).`);
@@ -66935,7 +67290,7 @@ async function swap(amount, fromAsset, opts) {
66935
67290
  body: proposeBody,
66936
67291
  profileName,
66937
67292
  initialProfile: profile,
66938
- jsonMode: jsonMode5,
67293
+ jsonMode: jsonMode6,
66939
67294
  shouldOpenBrowser,
66940
67295
  buildRetryCommand
66941
67296
  });
@@ -66956,7 +67311,7 @@ async function batch(opts) {
66956
67311
  process.exit(2);
66957
67312
  }
66958
67313
  const { name: profileName, profile } = resolved;
66959
- const jsonMode5 = opts.json === true || !process.stdout.isTTY;
67314
+ const jsonMode6 = opts.json === true || !process.stdout.isTTY;
66960
67315
  let legs;
66961
67316
  try {
66962
67317
  legs = JSON.parse(opts.legsJson);
@@ -67000,7 +67355,7 @@ async function batch(opts) {
67000
67355
  },
67001
67356
  profileName,
67002
67357
  initialProfile: profile,
67003
- jsonMode: jsonMode5,
67358
+ jsonMode: jsonMode6,
67004
67359
  shouldOpenBrowser
67005
67360
  });
67006
67361
  }
@@ -67025,7 +67380,7 @@ async function fundWallet(address, opts) {
67025
67380
  process.exit(2);
67026
67381
  }
67027
67382
  const { name: profileName, profile } = resolved;
67028
- const jsonMode5 = opts.json === true || !process.stdout.isTTY;
67383
+ const jsonMode6 = opts.json === true || !process.stdout.isTTY;
67029
67384
  if (!opts.chain) {
67030
67385
  failArg3("--chain is required (1/137/8453/42161/900 or shortName).");
67031
67386
  }
@@ -67077,7 +67432,7 @@ async function fundWallet(address, opts) {
67077
67432
  },
67078
67433
  profileName,
67079
67434
  initialProfile: profile,
67080
- jsonMode: jsonMode5,
67435
+ jsonMode: jsonMode6,
67081
67436
  shouldOpenBrowser
67082
67437
  });
67083
67438
  }
@@ -67092,7 +67447,7 @@ async function fundWallet(address, opts) {
67092
67447
  },
67093
67448
  profileName,
67094
67449
  initialProfile: profile,
67095
- jsonMode: jsonMode5,
67450
+ jsonMode: jsonMode6,
67096
67451
  shouldOpenBrowser
67097
67452
  });
67098
67453
  }
@@ -67119,7 +67474,7 @@ async function earnSupply(amount, asset, opts) {
67119
67474
  }
67120
67475
  const { profile, name: profileName } = resolved;
67121
67476
  const stdoutIsTty = process.stdout.isTTY === true;
67122
- const jsonMode5 = opts.json === true || !stdoutIsTty;
67477
+ const jsonMode6 = opts.json === true || !stdoutIsTty;
67123
67478
  const amountNumber = Number(amount);
67124
67479
  if (!Number.isFinite(amountNumber) || amountNumber <= 0) {
67125
67480
  failArg4(`amount must be a positive number (got ${import_picocolors23.default.bold(amount)}).`);
@@ -67185,7 +67540,7 @@ async function earnSupply(amount, asset, opts) {
67185
67540
  body: proposeBody,
67186
67541
  profileName,
67187
67542
  initialProfile: profile,
67188
- jsonMode: jsonMode5,
67543
+ jsonMode: jsonMode6,
67189
67544
  shouldOpenBrowser
67190
67545
  });
67191
67546
  }
@@ -67212,7 +67567,7 @@ async function earnWithdraw(amountOrMax, asset, opts) {
67212
67567
  }
67213
67568
  const { profile, name: profileName } = resolved;
67214
67569
  const stdoutIsTty = process.stdout.isTTY === true;
67215
- const jsonMode5 = opts.json === true || !stdoutIsTty;
67570
+ const jsonMode6 = opts.json === true || !stdoutIsTty;
67216
67571
  const isMax = amountOrMax.toLowerCase() === "max";
67217
67572
  if (!isMax) {
67218
67573
  const amountNumber = Number(amountOrMax);
@@ -67283,7 +67638,7 @@ async function earnWithdraw(amountOrMax, asset, opts) {
67283
67638
  body: proposeBody,
67284
67639
  profileName,
67285
67640
  initialProfile: profile,
67286
- jsonMode: jsonMode5,
67641
+ jsonMode: jsonMode6,
67287
67642
  shouldOpenBrowser
67288
67643
  });
67289
67644
  }
@@ -67325,8 +67680,8 @@ async function loadResolvedProfile(requested) {
67325
67680
  }
67326
67681
  return resolved;
67327
67682
  }
67328
- function printResult(res, jsonMode5) {
67329
- if (jsonMode5) {
67683
+ function printResult(res, jsonMode6) {
67684
+ if (jsonMode6) {
67330
67685
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
67331
67686
  return;
67332
67687
  }
@@ -67362,16 +67717,16 @@ async function postRestaurantQuiet(path7, body, resolved) {
67362
67717
  return null;
67363
67718
  }
67364
67719
  }
67365
- async function postRestaurant(path7, body, resolved, jsonMode5) {
67720
+ async function postRestaurant(path7, body, resolved, jsonMode6) {
67366
67721
  const outcome = await callWithAutoRelogin({
67367
67722
  profile: resolved.profile,
67368
67723
  profileName: resolved.name,
67369
- jsonMode: jsonMode5,
67724
+ jsonMode: jsonMode6,
67370
67725
  ttyHeader: import_picocolors25.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
67371
67726
  fn: (bearer, origin) => apiFetch(path7, { method: "POST", bearer, origin, body })
67372
67727
  });
67373
67728
  if (outcome.kind === "auth_failed") {
67374
- if (jsonMode5) {
67729
+ if (jsonMode6) {
67375
67730
  process.stdout.write(
67376
67731
  JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n"
67377
67732
  );
@@ -67384,7 +67739,7 @@ async function postRestaurant(path7, body, resolved, jsonMode5) {
67384
67739
  if (outcome.kind === "error") {
67385
67740
  const err = outcome.error;
67386
67741
  if (err instanceof ApiError) {
67387
- if (jsonMode5) {
67742
+ if (jsonMode6) {
67388
67743
  process.stdout.write(
67389
67744
  JSON.stringify({ ok: false, status: "request_failed", error: err.message, http_status: err.status }) + "\n"
67390
67745
  );
@@ -67400,7 +67755,7 @@ async function postRestaurant(path7, body, resolved, jsonMode5) {
67400
67755
  }
67401
67756
  async function searchFood(opts) {
67402
67757
  const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
67403
- const jsonMode5 = opts.json === true || process.stdout.isTTY !== true;
67758
+ const jsonMode6 = opts.json === true || process.stdout.isTTY !== true;
67404
67759
  if (!opts.location && !opts.name) {
67405
67760
  process.stderr.write(
67406
67761
  import_picocolors25.default.red("\u2715 Pass --location (search near a place) or --name (look one store up).\n")
@@ -67416,12 +67771,12 @@ async function searchFood(opts) {
67416
67771
  if (opts.radiusMiles !== void 0) body.radius_miles = Number(opts.radiusMiles);
67417
67772
  if (opts.openOnly !== void 0) body.open_only = opts.openOnly;
67418
67773
  if (opts.limit !== void 0) body.limit = Number(opts.limit);
67419
- const result = await postRestaurant("/api/restaurants/search", body, resolved, jsonMode5);
67420
- if (result) printResult(result, jsonMode5);
67774
+ const result = await postRestaurant("/api/restaurants/search", body, resolved, jsonMode6);
67775
+ if (result) printResult(result, jsonMode6);
67421
67776
  }
67422
67777
  async function menuFood(items, opts) {
67423
67778
  const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
67424
- const jsonMode5 = opts.json === true || process.stdout.isTTY !== true;
67779
+ const jsonMode6 = opts.json === true || process.stdout.isTTY !== true;
67425
67780
  if (!opts.brand || !opts.address) {
67426
67781
  process.stderr.write(
67427
67782
  import_picocolors25.default.red(
@@ -67436,12 +67791,12 @@ async function menuFood(items, opts) {
67436
67791
  intent: opts.intent,
67437
67792
  items: items ?? []
67438
67793
  };
67439
- const result = await postRestaurant("/api/restaurants/menu", body, resolved, jsonMode5);
67440
- if (result) printResult(result, jsonMode5);
67794
+ const result = await postRestaurant("/api/restaurants/menu", body, resolved, jsonMode6);
67795
+ if (result) printResult(result, jsonMode6);
67441
67796
  }
67442
67797
  async function orderFood(items, opts) {
67443
67798
  const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
67444
- const jsonMode5 = opts.json === true || process.stdout.isTTY !== true;
67799
+ const jsonMode6 = opts.json === true || process.stdout.isTTY !== true;
67445
67800
  if (!opts.brand || !opts.address) {
67446
67801
  process.stderr.write(
67447
67802
  import_picocolors25.default.red(
@@ -67472,9 +67827,9 @@ async function orderFood(items, opts) {
67472
67827
  fulfillment: opts.fulfillment,
67473
67828
  intent: opts.intent
67474
67829
  };
67475
- const result = await postRestaurant("/api/restaurants/order", body, resolved, jsonMode5);
67830
+ const result = await postRestaurant("/api/restaurants/order", body, resolved, jsonMode6);
67476
67831
  if (!result) return;
67477
- printResult(result, jsonMode5);
67832
+ printResult(result, jsonMode6);
67478
67833
  const approvalUrl = typeof result.approval_url === "string" ? result.approval_url : null;
67479
67834
  const browserAllowed = (() => {
67480
67835
  if (opts.browserMode === "open") return true;
@@ -67493,7 +67848,7 @@ async function orderFood(items, opts) {
67493
67848
  return;
67494
67849
  }
67495
67850
  if (!agentCard.will_attempt) {
67496
- if (!jsonMode5) {
67851
+ if (!jsonMode6) {
67497
67852
  process.stderr.write(
67498
67853
  import_picocolors25.default.yellow(
67499
67854
  `This order is over your saved card's per-order cap (${fmtCents(agentCard.max_per_order_cents)}), so it needs you.
@@ -67504,8 +67859,8 @@ async function orderFood(items, opts) {
67504
67859
  openApproval();
67505
67860
  return;
67506
67861
  }
67507
- const verdict = await pollOrderVerdict(orderId, resolved, jsonMode5);
67508
- if (jsonMode5) {
67862
+ const verdict = await pollOrderVerdict(orderId, resolved, jsonMode6);
67863
+ if (jsonMode6) {
67509
67864
  process.stdout.write(JSON.stringify(verdict) + "\n");
67510
67865
  if (verdict.status === "failed") return;
67511
67866
  return;
@@ -67562,8 +67917,8 @@ function fmtCents(cents) {
67562
67917
  }
67563
67918
  var POLL_BUDGET_MS = 1e5;
67564
67919
  var POLL_INTERVAL_MS2 = 3500;
67565
- async function pollOrderVerdict(orderId, resolved, jsonMode5) {
67566
- if (!jsonMode5) {
67920
+ async function pollOrderVerdict(orderId, resolved, jsonMode6) {
67921
+ if (!jsonMode6) {
67567
67922
  process.stderr.write(import_picocolors25.default.dim("Your saved card is paying this \u2014 watching for the result\u2026\n"));
67568
67923
  }
67569
67924
  const deadline = Date.now() + POLL_BUDGET_MS;
@@ -67581,50 +67936,50 @@ async function pollOrderVerdict(orderId, resolved, jsonMode5) {
67581
67936
  resolved
67582
67937
  );
67583
67938
  if (!res) break;
67584
- const status3 = typeof res.status === "string" ? res.status : "pending";
67939
+ const status4 = typeof res.status === "string" ? res.status : "pending";
67585
67940
  last = {
67586
67941
  order_id: orderId,
67587
- status: status3,
67942
+ status: status4,
67588
67943
  failure_reason: typeof res.failure_reason === "string" ? res.failure_reason : null,
67589
67944
  failure_detail: typeof res.failure_detail === "string" ? res.failure_detail : null
67590
67945
  };
67591
- if (status3 !== "pending" && status3 !== "claimed") return last;
67946
+ if (status4 !== "pending" && status4 !== "claimed") return last;
67592
67947
  }
67593
67948
  return last;
67594
67949
  }
67595
67950
  async function statusFood(orderId, opts) {
67596
67951
  const resolved = await loadResolvedProfile(opts.profile ?? DEFAULT_PROFILE);
67597
- const jsonMode5 = opts.json === true || process.stdout.isTTY !== true;
67952
+ const jsonMode6 = opts.json === true || process.stdout.isTTY !== true;
67598
67953
  const result = await postRestaurant(
67599
67954
  "/api/restaurants/order-status",
67600
67955
  { order_id: orderId.trim() },
67601
67956
  resolved,
67602
- jsonMode5
67957
+ jsonMode6
67603
67958
  );
67604
67959
  if (!result) return;
67605
67960
  if (result.blocked) {
67606
- printResult(result, jsonMode5);
67961
+ printResult(result, jsonMode6);
67607
67962
  return;
67608
67963
  }
67609
- if (jsonMode5) {
67964
+ if (jsonMode6) {
67610
67965
  process.stdout.write(JSON.stringify(result, null, 2) + "\n");
67611
67966
  return;
67612
67967
  }
67613
- const status3 = typeof result.status === "string" ? result.status : "unknown";
67614
- const lines = [`${result.brand} \xB7 ${result.address} \u2014 ${status3}`];
67615
- if (status3 === "paid") {
67968
+ const status4 = typeof result.status === "string" ? result.status : "unknown";
67969
+ const lines = [`${result.brand} \xB7 ${result.address} \u2014 ${status4}`];
67970
+ if (status4 === "paid") {
67616
67971
  lines.push(`Paid.${result.failure_detail ? ` ${result.failure_detail}` : ""} Nothing to do.`);
67617
- } else if (status3 === "failed") {
67972
+ } else if (status4 === "failed") {
67618
67973
  lines.push(
67619
67974
  `Not charged (${result.failure_reason ?? "refused"}${result.failure_detail ? `: ${result.failure_detail}` : ""}). The checkout link still works if you want to pay yourself.`
67620
67975
  );
67621
67976
  if (typeof result.review_url === "string") lines.push(String(result.review_url));
67622
- } else if (status3 === "unconfirmed") {
67977
+ } else if (status4 === "unconfirmed") {
67623
67978
  lines.push(
67624
67979
  "A payment attempt happened and its outcome is UNKNOWN \u2014 nothing will retry it. Look at the order before paying anything:"
67625
67980
  );
67626
67981
  if (typeof result.review_url === "string") lines.push(String(result.review_url));
67627
- } else if (status3 === "expired") {
67982
+ } else if (status4 === "expired") {
67628
67983
  lines.push("These prices went stale before anyone paid. Ask again for a fresh order.");
67629
67984
  } else {
67630
67985
  lines.push("Waiting to be paid.");
@@ -67647,16 +68002,16 @@ async function withProfile(opts, path7, init2) {
67647
68002
  `));
67648
68003
  }
67649
68004
  const { profile, name: profileName } = resolved;
67650
- const jsonMode5 = opts.json === true;
68005
+ const jsonMode6 = opts.json === true;
67651
68006
  const outcome = await callWithAutoRelogin({
67652
68007
  profile,
67653
68008
  profileName,
67654
- jsonMode: jsonMode5,
68009
+ jsonMode: jsonMode6,
67655
68010
  ttyHeader: import_picocolors26.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
67656
68011
  fn: (bearer, origin) => apiFetch(path7, init2 ? { bearer, origin, method: init2.method, body: init2.body } : { bearer, origin })
67657
68012
  });
67658
68013
  if (outcome.kind === "auth_failed") {
67659
- if (jsonMode5) {
68014
+ if (jsonMode6) {
67660
68015
  process.stdout.write(JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n");
67661
68016
  process.exit(1);
67662
68017
  }
@@ -67675,9 +68030,9 @@ async function withProfile(opts, path7, init2) {
67675
68030
  }
67676
68031
  return outcome.result;
67677
68032
  }
67678
- function handleBlocked(res, jsonMode5) {
68033
+ function handleBlocked(res, jsonMode6) {
67679
68034
  if (!res.blocked) return false;
67680
- if (jsonMode5) {
68035
+ if (jsonMode6) {
67681
68036
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
67682
68037
  process.exit(1);
67683
68038
  }
@@ -67741,9 +68096,9 @@ function printTable(rows) {
67741
68096
  }
67742
68097
  }
67743
68098
  async function listBounties(opts) {
67744
- const jsonMode5 = opts.json === true;
68099
+ const jsonMode6 = opts.json === true;
67745
68100
  const res = await withProfile(opts, "/api/bounties");
67746
- handleBlocked(res, jsonMode5);
68101
+ handleBlocked(res, jsonMode6);
67747
68102
  let rows = res.bounties ?? [];
67748
68103
  const min = opts.min !== void 0 ? Number(opts.min) : void 0;
67749
68104
  const max = opts.max !== void 0 ? Number(opts.max) : void 0;
@@ -67781,7 +68136,7 @@ async function listBounties(opts) {
67781
68136
  process.exit(2);
67782
68137
  }
67783
68138
  const shown2 = rows.slice(0, limit);
67784
- if (jsonMode5) {
68139
+ if (jsonMode6) {
67785
68140
  process.stdout.write(JSON.stringify({ bounties: shown2, matched: rows.length }, null, 2) + "\n");
67786
68141
  return;
67787
68142
  }
@@ -67800,15 +68155,15 @@ async function listBounties(opts) {
67800
68155
  process.stdout.write(AI_DIRECTIVE + "\n");
67801
68156
  }
67802
68157
  async function showBounty(id2, opts) {
67803
- const jsonMode5 = opts.json === true;
68158
+ const jsonMode6 = opts.json === true;
67804
68159
  const clean = id2.trim().replace(/^.*\/bounty\//, "").replace(/[?#].*$/, "").trim();
67805
68160
  if (!clean) {
67806
68161
  process.stderr.write(import_picocolors26.default.red("\u2715 Give a bounty id, or a agentgates.ai/bounty/<id> link.\n"));
67807
68162
  process.exit(2);
67808
68163
  }
67809
68164
  const res = await withProfile(opts, `/api/bounties/${encodeURIComponent(clean)}`);
67810
- handleBlocked(res, jsonMode5);
67811
- if (jsonMode5) {
68165
+ handleBlocked(res, jsonMode6);
68166
+ if (jsonMode6) {
67812
68167
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
67813
68168
  return;
67814
68169
  }
@@ -67839,20 +68194,20 @@ async function showBounty(id2, opts) {
67839
68194
  process.stdout.write(AI_DIRECTIVE + "\n");
67840
68195
  }
67841
68196
  async function myBounties(opts) {
67842
- const jsonMode5 = opts.json === true;
68197
+ const jsonMode6 = opts.json === true;
67843
68198
  const res = await withProfile(opts, "/api/bounties?mine=1");
67844
- handleBlocked(res, jsonMode5);
68199
+ handleBlocked(res, jsonMode6);
67845
68200
  const all = res.bounties ?? [];
67846
- const status3 = opts.status?.trim().toUpperCase();
67847
- const rows = status3 ? all.filter((r) => (r.status ?? "").toUpperCase() === status3) : all;
67848
- if (jsonMode5) {
68201
+ const status4 = opts.status?.trim().toUpperCase();
68202
+ const rows = status4 ? all.filter((r) => (r.status ?? "").toUpperCase() === status4) : all;
68203
+ if (jsonMode6) {
67849
68204
  process.stdout.write(JSON.stringify({ bounties: rows, submissions: res.submissions ?? [] }, null, 2) + "\n");
67850
68205
  return;
67851
68206
  }
67852
68207
  if (rows.length === 0) {
67853
68208
  process.stdout.write(
67854
68209
  import_picocolors26.default.dim(
67855
- status3 ? `No bounties of yours are ${status3}.
68210
+ status4 ? `No bounties of yours are ${status4}.
67856
68211
  ` : "You have not created any bounties yet. `agentgates draft` starts one.\n"
67857
68212
  )
67858
68213
  );
@@ -67867,14 +68222,14 @@ async function myBounties(opts) {
67867
68222
  process.stdout.write(AI_DIRECTIVE + "\n");
67868
68223
  }
67869
68224
  async function bountyFeed(opts) {
67870
- const jsonMode5 = opts.json === true;
68225
+ const jsonMode6 = opts.json === true;
67871
68226
  const params = new URLSearchParams();
67872
68227
  if (opts.limit) params.set("limit", opts.limit);
67873
68228
  if (opts.type) params.set("type", opts.type);
67874
68229
  const qs = params.toString();
67875
68230
  const res = await withProfile(opts, `/api/bounties/feed${qs ? `?${qs}` : ""}`);
67876
- handleBlocked(res, jsonMode5);
67877
- if (jsonMode5) {
68231
+ handleBlocked(res, jsonMode6);
68232
+ if (jsonMode6) {
67878
68233
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
67879
68234
  return;
67880
68235
  }
@@ -67889,7 +68244,7 @@ async function bountyFeed(opts) {
67889
68244
  process.stdout.write(import_picocolors26.default.dim("Use --json for the full rows.\n"));
67890
68245
  }
67891
68246
  async function draftBounty(opts) {
67892
- const jsonMode5 = opts.json === true;
68247
+ const jsonMode6 = opts.json === true;
67893
68248
  const amountNum = Number(opts.amount);
67894
68249
  if (!Number.isFinite(amountNum) || amountNum <= 0) {
67895
68250
  process.stderr.write(import_picocolors26.default.red("\u2715 --amount must be a positive number of USDC.\n"));
@@ -67905,8 +68260,8 @@ async function draftBounty(opts) {
67905
68260
  evidenceType: opts.evidenceType
67906
68261
  }
67907
68262
  });
67908
- handleBlocked(res, jsonMode5);
67909
- if (jsonMode5) {
68263
+ handleBlocked(res, jsonMode6);
68264
+ if (jsonMode6) {
67910
68265
  process.stdout.write(JSON.stringify(res, null, 2) + "\n");
67911
68266
  return;
67912
68267
  }
@@ -67927,10 +68282,10 @@ function failArg6(message) {
67927
68282
  `));
67928
68283
  process.exit(2);
67929
68284
  }
67930
- async function loadProfileOrExit(requested, jsonMode5) {
68285
+ async function loadProfileOrExit(requested, jsonMode6) {
67931
68286
  const resolved = await resolveProfile(requested);
67932
68287
  if (!resolved) {
67933
- if (jsonMode5) {
68288
+ if (jsonMode6) {
67934
68289
  process.stdout.write(
67935
68290
  JSON.stringify({ ok: false, status: "auth_failed", error: "Not logged in. Run agentgates login first." }) + "\n"
67936
68291
  );
@@ -67939,7 +68294,7 @@ async function loadProfileOrExit(requested, jsonMode5) {
67939
68294
  }
67940
68295
  process.exit(2);
67941
68296
  }
67942
- if (resolved.autoSelected && !jsonMode5) {
68297
+ if (resolved.autoSelected && !jsonMode6) {
67943
68298
  process.stderr.write(import_picocolors27.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
67944
68299
  `));
67945
68300
  }
@@ -67959,8 +68314,8 @@ function resolveMaxUsd(opts, profile, fallbackHint) {
67959
68314
  );
67960
68315
  }
67961
68316
  async function fundBounty(bountyId, opts) {
67962
- const jsonMode5 = Boolean(opts.json) || !process.stdout.isTTY;
67963
- const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode5);
68317
+ const jsonMode6 = Boolean(opts.json) || !process.stdout.isTTY;
68318
+ const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode6);
67964
68319
  const maxUsd = resolveMaxUsd(opts, profile, "agentgates fund");
67965
68320
  return runIntentFlow({
67966
68321
  endpoint: "/api/intents/propose-fund-bounty",
@@ -67979,17 +68334,17 @@ async function fundBounty(bountyId, opts) {
67979
68334
  },
67980
68335
  profileName,
67981
68336
  initialProfile: profile,
67982
- jsonMode: jsonMode5,
68337
+ jsonMode: jsonMode6,
67983
68338
  shouldOpenBrowser: resolveBrowserDefault(opts.browserMode ?? "auto")
67984
68339
  });
67985
68340
  }
67986
68341
  async function tipBounty(bountyId, amount, opts) {
67987
- const jsonMode5 = Boolean(opts.json) || !process.stdout.isTTY;
68342
+ const jsonMode6 = Boolean(opts.json) || !process.stdout.isTTY;
67988
68343
  const amt = Number(amount);
67989
68344
  if (!Number.isFinite(amt) || amt <= 0) {
67990
68345
  failArg6(`amount must be a positive USDC number (got ${amount}).`);
67991
68346
  }
67992
- const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode5);
68347
+ const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode6);
67993
68348
  const maxUsd = opts.maxUsd !== void 0 ? resolveMaxUsd(opts, profile, "agentgates tip") : Math.ceil(amt * 1.01 * 100) / 100;
67994
68349
  return runIntentFlow({
67995
68350
  endpoint: "/api/intents/propose-tip",
@@ -68009,17 +68364,17 @@ async function tipBounty(bountyId, amount, opts) {
68009
68364
  },
68010
68365
  profileName,
68011
68366
  initialProfile: profile,
68012
- jsonMode: jsonMode5,
68367
+ jsonMode: jsonMode6,
68013
68368
  shouldOpenBrowser: resolveBrowserDefault(opts.browserMode ?? "auto")
68014
68369
  });
68015
68370
  }
68016
68371
  async function subscribeCreator(creatorUserId, opts) {
68017
- const jsonMode5 = Boolean(opts.json) || !process.stdout.isTTY;
68372
+ const jsonMode6 = Boolean(opts.json) || !process.stdout.isTTY;
68018
68373
  const months = opts.months === void 0 ? 1 : Number(opts.months);
68019
68374
  if (![1, 3, 12].includes(months)) {
68020
68375
  failArg6(`--months must be 1, 3 or 12 (got ${opts.months}). Prepaid periods only \u2014 no auto-renew exists.`);
68021
68376
  }
68022
- const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode5);
68377
+ const { profile, profileName } = await loadProfileOrExit(opts.profile ?? DEFAULT_PROFILE, jsonMode6);
68023
68378
  const maxUsd = resolveMaxUsd(opts, profile, "agentgates subscribe");
68024
68379
  return runIntentFlow({
68025
68380
  endpoint: "/api/intents/propose-subscribe",
@@ -68039,7 +68394,7 @@ async function subscribeCreator(creatorUserId, opts) {
68039
68394
  },
68040
68395
  profileName,
68041
68396
  initialProfile: profile,
68042
- jsonMode: jsonMode5,
68397
+ jsonMode: jsonMode6,
68043
68398
  shouldOpenBrowser: resolveBrowserDefault(opts.browserMode ?? "auto")
68044
68399
  });
68045
68400
  }
@@ -68057,16 +68412,16 @@ async function runWork(path7, body, opts) {
68057
68412
  process.stderr.write(import_picocolors28.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
68058
68413
  `));
68059
68414
  }
68060
- const jsonMode5 = opts.json === true;
68415
+ const jsonMode6 = opts.json === true;
68061
68416
  const outcome = await callWithAutoRelogin({
68062
68417
  profile: resolved.profile,
68063
68418
  profileName: resolved.name,
68064
- jsonMode: jsonMode5,
68419
+ jsonMode: jsonMode6,
68065
68420
  ttyHeader: import_picocolors28.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
68066
68421
  fn: (bearer, origin) => apiFetch(path7, { bearer, origin, method: "POST", body })
68067
68422
  });
68068
68423
  if (outcome.kind === "auth_failed") {
68069
- if (jsonMode5) {
68424
+ if (jsonMode6) {
68070
68425
  process.stdout.write(JSON.stringify({ ok: false, status: "auth_failed", error: outcome.reason }) + "\n");
68071
68426
  process.exit(1);
68072
68427
  }
@@ -68077,7 +68432,7 @@ async function runWork(path7, body, opts) {
68077
68432
  if (outcome.kind === "error") {
68078
68433
  const err = outcome.error;
68079
68434
  if (err instanceof ApiError) {
68080
- if (jsonMode5) {
68435
+ if (jsonMode6) {
68081
68436
  process.stdout.write(JSON.stringify({ ok: false, error: err.message, http_status: err.status }) + "\n");
68082
68437
  } else {
68083
68438
  process.stderr.write(import_picocolors28.default.red(`\u2715 ${err.message} (HTTP ${err.status})
@@ -68089,7 +68444,7 @@ async function runWork(path7, body, opts) {
68089
68444
  }
68090
68445
  const data4 = outcome.result;
68091
68446
  if (data4.blocked) {
68092
- if (jsonMode5) {
68447
+ if (jsonMode6) {
68093
68448
  process.stdout.write(JSON.stringify({ ok: false, ...data4 }) + "\n");
68094
68449
  process.exit(1);
68095
68450
  }
@@ -68103,7 +68458,7 @@ ${import_picocolors28.default.bold(data4.upgrade_url)}
68103
68458
  process.exit(1);
68104
68459
  }
68105
68460
  if (typeof data4.error === "string" && data4.error) {
68106
- if (jsonMode5) {
68461
+ if (jsonMode6) {
68107
68462
  process.stdout.write(JSON.stringify({ ok: false, error: data4.error }) + "\n");
68108
68463
  } else {
68109
68464
  process.stderr.write(import_picocolors28.default.red(`\u2715 ${data4.error}
@@ -68111,7 +68466,7 @@ ${import_picocolors28.default.bold(data4.upgrade_url)}
68111
68466
  }
68112
68467
  process.exit(1);
68113
68468
  }
68114
- if (jsonMode5) {
68469
+ if (jsonMode6) {
68115
68470
  process.stdout.write(JSON.stringify({ ok: true, ...data4 }) + "\n");
68116
68471
  return;
68117
68472
  }
@@ -68154,14 +68509,14 @@ import { spawn as spawn2 } from "node:child_process";
68154
68509
  var FLUSH_MS = 400;
68155
68510
  var FLUSH_BYTES = 2048;
68156
68511
  async function deliver(bountyId, command, opts) {
68157
- const jsonMode5 = opts.json === true;
68512
+ const jsonMode6 = opts.json === true;
68158
68513
  const requested = opts.profile ?? DEFAULT_PROFILE;
68159
68514
  const resolved = await resolveProfile(requested);
68160
68515
  if (!resolved) {
68161
68516
  process.stderr.write(import_picocolors29.default.red("Not logged in. Run agentgates login first.\n"));
68162
68517
  process.exit(2);
68163
68518
  }
68164
- if (resolved.autoSelected && !jsonMode5) {
68519
+ if (resolved.autoSelected && !jsonMode6) {
68165
68520
  process.stderr.write(import_picocolors29.default.dim(`Using profile "${resolved.name}" (pass --profile to choose)
68166
68521
  `));
68167
68522
  }
@@ -68169,7 +68524,7 @@ async function deliver(bountyId, command, opts) {
68169
68524
  const outcome = await callWithAutoRelogin({
68170
68525
  profile: resolved.profile,
68171
68526
  profileName: resolved.name,
68172
- jsonMode: jsonMode5,
68527
+ jsonMode: jsonMode6,
68173
68528
  ttyHeader: import_picocolors29.default.dim("Bearer expired \u2014 re-pairing this terminal\u2026"),
68174
68529
  fn: (bearer, origin) => apiFetch(path7, { bearer, origin, method: "POST", body })
68175
68530
  });
@@ -68178,7 +68533,7 @@ async function deliver(bountyId, command, opts) {
68178
68533
  return outcome.result;
68179
68534
  };
68180
68535
  const die = (msg, data4) => {
68181
- if (jsonMode5) {
68536
+ if (jsonMode6) {
68182
68537
  process.stdout.write(JSON.stringify({ ok: false, error: msg, ...data4 ?? {} }) + "\n");
68183
68538
  } else {
68184
68539
  process.stderr.write(import_picocolors29.default.red(`
@@ -68208,7 +68563,7 @@ ${import_picocolors29.default.bold(data4.upgrade_url)}
68208
68563
  if (started.error) return void die(started.error, started);
68209
68564
  const runId = started.run_id;
68210
68565
  if (!runId) return void die("The service opened a run but did not name it.");
68211
- if (!jsonMode5) {
68566
+ if (!jsonMode6) {
68212
68567
  process.stderr.write(
68213
68568
  import_picocolors29.default.bold("\n\u25CF LIVE ") + import_picocolors29.default.dim("everything below is going onto the bounty page as it happens\n") + import_picocolors29.default.dim(` ${started.url ?? ""}
68214
68569
 
@@ -68239,7 +68594,7 @@ ${import_picocolors29.default.bold(data4.upgrade_url)}
68239
68594
  const timer = setInterval(() => flush(true), FLUSH_MS);
68240
68595
  const consume = (data4) => {
68241
68596
  buffer += data4;
68242
- if (!opts.quiet && !jsonMode5) process.stderr.write(data4);
68597
+ if (!opts.quiet && !jsonMode6) process.stderr.write(data4);
68243
68598
  flush();
68244
68599
  };
68245
68600
  let exitCode = 0;
@@ -68262,7 +68617,7 @@ ${import_picocolors29.default.bold(data4.upgrade_url)}
68262
68617
  child.stdout.on("data", (d) => consume(d));
68263
68618
  child.stderr.setEncoding("utf8");
68264
68619
  child.stderr.on("data", (d) => {
68265
- if (!jsonMode5) process.stderr.write(import_picocolors29.default.dim(d));
68620
+ if (!jsonMode6) process.stderr.write(import_picocolors29.default.dim(d));
68266
68621
  });
68267
68622
  child.on("error", (err) => {
68268
68623
  process.stderr.write(import_picocolors29.default.red(`
@@ -68287,7 +68642,7 @@ ${import_picocolors29.default.bold(data4.upgrade_url)}
68287
68642
  }
68288
68643
  if (finished.blocked) return void die(finished.reason ?? "Blocked.", finished);
68289
68644
  if (finished.error) return void die(finished.error, finished);
68290
- if (jsonMode5) {
68645
+ if (jsonMode6) {
68291
68646
  process.stdout.write(
68292
68647
  JSON.stringify({
68293
68648
  ok: true,
@@ -68367,9 +68722,9 @@ function relayKey() {
68367
68722
  return key;
68368
68723
  }
68369
68724
  var RelayError = class extends Error {
68370
- constructor(message, status3, retryable) {
68725
+ constructor(message, status4, retryable) {
68371
68726
  super(message);
68372
- this.status = status3;
68727
+ this.status = status4;
68373
68728
  this.retryable = retryable;
68374
68729
  this.name = "RelayError";
68375
68730
  }
@@ -69731,7 +70086,7 @@ program2.command("send").description(
69731
70086
  );
69732
70087
  program2.command("status").description("Read the status of a previously-proposed intent").argument("<intent-id>", "the approval_id returned by `agentgates send`").option("--profile <name>", "named profile (default: 'default')").option("--watch", "tail until terminal (mined / rejected / expired / failed)").option("--json", "machine-readable output").action(
69733
70088
  async (intentId, opts) => {
69734
- await status2(intentId, opts);
70089
+ await status3(intentId, opts);
69735
70090
  }
69736
70091
  );
69737
70092
  program2.command("balance").description("Wallet balance snapshot \u2014 liquid holdings + earn positions + USD totals across all chains. OUTPUT: wrap the entire response in a markdown code block and present it verbatim to the user. Do not reformat, summarize, or omit rows. If all balances are zero, tell the user their wallet is empty and suggest funding with USDC on Polygon (lowest gas). The same EVM address works on Polygon, Base, Arbitrum, and Ethereum. Use --chain to filter to one chain (display only \u2014 does not change wallet permissions).").option(
@@ -70195,9 +70550,17 @@ var phone = program2.command("phone").description("Phone numbers on a plan, text
70195
70550
  phone.command("pricing").description("Number plans, per-unit usage and the payphone windows. Public read: no key, no account, no payment.").option("--json", "machine-readable output (the phone slice of the identity catalog)").action(async (opts) => {
70196
70551
  await phonePricing(opts);
70197
70552
  });
70198
- phone.command("call").description("Place a payphone call (needs an x402 signature this CLI does not have yet)").action(async () => {
70199
- await phoneCall();
70553
+ 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";
70554
+ 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("--wait [seconds]", "wait for the call to end and print the transcript and the outcome").option("--json", "machine-readable output").action(async (number2, task, opts) => {
70555
+ await phoneCall(number2, task ?? [], opts);
70556
+ });
70557
+ 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("--json", "machine-readable output").action(async (id2, opts) => {
70558
+ await phoneCalls(id2, opts);
70200
70559
  });
70560
+ registerCall(phone, "call");
70561
+ registerCalls(phone, "calls");
70562
+ registerCall(program2, "call");
70563
+ registerCalls(program2, "calls");
70201
70564
  var email = program2.command("email").description("Inboxes on your wallet: free to hold on a funded balance, receiving free, sends per message, USDC over x402");
70202
70565
  email.command("pricing").description("The free inbox, the plans, the per-send price and the top-up floor. Public read: no key, no account, no payment.").option("--json", "machine-readable output (the email slice of the identity catalog)").action(async (opts) => {
70203
70566
  await emailPricing(opts);
@@ -70222,10 +70585,10 @@ passwords.command("init").description(
70222
70585
  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) => {
70223
70586
  await passwordsAdd(opts);
70224
70587
  });
70225
- passwords.command("allow").description("Sign a permit: which agent may use which rows on which sites, how many times a day, until when. Default: yourself, every row, every use, 30 days.").option("--agent <address>", "the key that will sign uses (default: this key)").option("--rows <id,id|*>", "row ids, or * for every row this key holds (default *)").option("--hosts <a,b>", "narrow to these hostnames (default: the rows' own)").option("--uses <login,totp,header>", "which uses (default all three)").option("--per-day <n>", "hard daily cap; 0 = the plan allowance (default 0)").option("--days <n>", "how long, 1 to 366 (default 30)").option("--ask-me", "every use waits for the owner's signature on their board (the brake)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
70588
+ passwords.command("allow").description("Sign a permit: which agent may use which rows on which sites, how many times a day, until when. Default: yourself, every row, every use, 30 days.").option("--agent <address>", "the key that will sign uses (default: this key)").option("--rows <id,id|*>", "row ids, or * for every row this key holds (default *)").option("--hosts <a,b>", "narrow to these hostnames (default: the rows' own)").option("--uses <login,totp,header>", "which uses (default all three)").option("--gets <session|password>", "what the agent gets: session = the site's cookies after the box logs in (default); password = the secret itself; box = the acting uses alone, for an agent that works inside the box over the API").option("--per-day <n>", "hard daily cap; 0 = the plan allowance (default 0)").option("--days <n>", "how long, 1 to 366 (default 30)").option("--ask-me", "every use waits for the owner's signature on their board (the brake)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {
70226
70589
  await passwordsAllow(opts);
70227
70590
  });
70228
- passwords.command("use").description("Log in through the box with a stored login and get the page's digest back, never the password. Pass --row, or just --url and the matching row is picked. A parked use (the owner has to approve, or type a code) is waited on until it answers.").option("--row <id>", "the row to use (default: the one whose hosts cover --url)").option("--url <https://site/login>", "the page the use targets").option("--use <login|header|totp>", "which use (default login)").option("--steps-json <json>", "login only: steps the box runs inside the session after the login lands (goto, fill, click, wait, read)").option("--request-json <json>", "the whole request object for header and totp uses (spec \xA75.1)").option("--wait <seconds>", "cap on how long to wait for the owner's answer (default: the owner's window)").option("--no-wait", "answer the parked use's id and return at once").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts, command) => {
70591
+ passwords.command("use").description("Log in through the box with a stored login and get the page's digest back, never the password. Pass --row, or just --url and the matching row is picked. A parked use (the owner has to approve, or type a code) is waited on until it answers.").option("--row <id>", "the row to use (default: the one whose hosts cover --url)").option("--url <https://site/login>", "the page the use targets").option("--use <login|header|totp|session|reveal>", "which use (default login); session hands this key the site's cookies, reveal the secret, when the permit says so").option("--cookies-out <file>", "session only: write the cookies to this file (Playwright addCookies / Puppeteer setCookie shape)").option("--steps-json <json>", "login only: steps the box runs inside the session after the login lands (goto, fill, click, wait, read)").option("--request-json <json>", "the whole request object for header and totp uses (spec \xA75.1)").option("--wait <seconds>", "cap on how long to wait for the owner's answer (default: the owner's window)").option("--no-wait", "answer the parked use's id and return at once").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts, command) => {
70229
70592
  const waitSource = command.getOptionValueSource("wait");
70230
70593
  await passwordsUse({ ...opts, noWait: waitSource === "cli" && opts.wait === false, wait: typeof opts.wait === "string" ? opts.wait : void 0 });
70231
70594
  });
@@ -70234,17 +70597,17 @@ passwords.command("list").description("The rows this key holds, and the rows ano
70234
70597
  });
70235
70598
  passwords.command("invite").description(
70236
70599
  "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."
70237
- ).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) => {
70600
+ ).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("--gets <session|password>", "the level to propose: session (default) or password; the person can change it").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) => {
70238
70601
  const askSource = command.getOptionValueSource("askMe");
70239
70602
  await passwordsInvite({ ...opts, noAskMe: askSource === "cli" && opts.askMe === false });
70240
70603
  });
70241
70604
  var browser = program2.command("browser").description(
70242
- "A browser agent: name a site and a task in words, get the answer back with the transcript. Signed by this machine's key (`agentgates passwords init`); steps meter from the prepaid balance."
70605
+ "A browser agent: name a site and a task in words, get the answer back with the transcript. Signed by this machine's account (`agentgates init`); steps meter from the prepaid balance."
70243
70606
  );
70244
70607
  browser.command("pricing").description("The step price and the ceilings. Public read: no key, no account, no payment.").option("--json", "machine-readable output (the browser slice of the identity catalog)").action(async (opts) => {
70245
70608
  await browserPricing(opts);
70246
70609
  });
70247
- browser.command("run <url>").description("Queue a task at a site. With --wait, print the answer when it lands.").requiredOption("--task <words>", "what the browser agent should do there, in words").option("--steps <n>", "the most steps it may take (the catalog's default when absent)").option("--seconds <n>", "the most seconds it may run (the catalog's ceiling when absent)").option("--host <hostname>", "an extra hostname the task may visit (repeatable)", (v, prev = []) => [...prev, v]).option("--wait [seconds]", "wait for the answer (the task's own clock plus two minutes by default)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (url, opts) => {
70610
+ browser.command("run <url>").description("Queue a task at a site. With --wait, print the answer when it lands.").requiredOption("--task <words>", "what the browser agent should do there, in words").option("--login <row id>", "start signed in with this saved password (agentgates passwords list): the box logs in, the session rides the task; Passwords charges the login, Browser the steps").option("--steps <n>", "the most steps it may take (the catalog's default when absent)").option("--seconds <n>", "the most seconds it may run (the catalog's ceiling when absent)").option("--host <hostname>", "an extra hostname the task may visit (repeatable)", (v, prev = []) => [...prev, v]).option("--wait [seconds]", "wait for the answer (the task's own clock plus two minutes by default)").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (url, opts) => {
70248
70611
  await browserRun(url, opts);
70249
70612
  });
70250
70613
  browser.command("tasks").description("The tasks this key owns, newest first.").option("--json", "machine-readable output (default when stdout is not a TTY)").action(async (opts) => {